home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 41 / Amiga Format CD41 (1999-06)(Future Publishing)(GB)[!][issue 1999-07].iso / -seriously_amiga- / programming / other / scm / slib / slib.info (.txt) < prev    next >
GNU Info File  |  1999-04-19  |  465KB  |  9,089 lines

  1. This is Info file slib.info, produced by Makeinfo version 1.68 from the
  2. input file slib.texi.
  3. INFO-DIR-SECTION The Algorithmic Language Scheme
  4. START-INFO-DIR-ENTRY
  5. * SLIB: (slib).         Scheme Library
  6. END-INFO-DIR-ENTRY
  7.   This file documents SLIB, the portable Scheme library.
  8.   Copyright (C) 1993 Todd R. Eigenschink
  9. Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998 Aubrey Jaffer
  10.   Permission is granted to make and distribute verbatim copies of this
  11. manual provided the copyright notice and this permission notice are
  12. preserved on all copies.
  13.   Permission is granted to copy and distribute modified versions of this
  14. manual under the conditions for verbatim copying, provided that the
  15. entire resulting derived work is distributed under the terms of a
  16. permission notice identical to this one.
  17.   Permission is granted to copy and distribute translations of this
  18. manual into another language, under the above conditions for modified
  19. versions, except that this permission notice may be stated in a
  20. translation approved by the author.
  21. File: slib.info,  Node: Top,  Next: The Library System,  Prev: (dir),  Up: (dir)
  22.   "SLIB" is a portable library for the programming language "Scheme".
  23. It provides a platform independent framework for using "packages" of
  24. Scheme procedures and syntax.  As distributed, SLIB contains useful
  25. packages for all implementations.  Its catalog can be transparently
  26. extended to accomodate packages specific to a site, implementation,
  27. user, or directory.
  28.      Aubrey Jaffer <jaffer @ ai.mit.edu>
  29.      Hyperactive Software - The Maniac Inside!
  30.      `http://swissnet.ai.mit.edu/~jaffer/SLIB.html'
  31. * Menu:
  32. * The Library System::          How to use and customize.
  33. * Scheme Syntax Extension Packages::
  34. * Textual Conversion Packages::
  35. * Mathematical Packages::
  36. * Database Packages::
  37. * Other Packages::
  38. * About SLIB::                  Install, etc.
  39. * Index::
  40. File: slib.info,  Node: The Library System,  Next: Scheme Syntax Extension Packages,  Prev: Top,  Up: Top
  41. The Library System
  42. ******************
  43. * Menu:
  44. * Feature::                     SLIB names.
  45. * Requesting Features::
  46. * Library Catalogs::
  47. * Catalog Compilation::
  48. * Built-in Support::
  49. * About this manual::
  50. File: slib.info,  Node: Feature,  Next: Requesting Features,  Prev: The Library System,  Up: The Library System
  51. Feature
  52. =======
  53. SLIB denotes "features" by symbols.  SLIB maintains a list of features
  54. supported by the Scheme "session".  The set of features provided by a
  55. session may change over time.  Some features are properties of the
  56. Scheme implementation being used.  The following features detail what
  57. sort of numbers are available from an implementation.
  58.    * 'inexact
  59.    * 'rational
  60.    * 'real
  61.    * 'complex
  62.    * 'bignum
  63. Other features correspond to the presence of sets of Scheme procedures
  64. or syntax (macros).
  65.  - Function: provided? FEATURE
  66.      Returns `#t' if FEATURE is supported by the current Scheme session.
  67.  - Procedure: provide FEATURE
  68.      Informs SLIB that FEATURE is supported.  Henceforth `(provided?
  69.      FEATURE)' will return `#t'.
  70.      (provided? 'foo)    => #f
  71.      (provide 'foo)
  72.      (provided? 'foo)    => #t
  73. File: slib.info,  Node: Requesting Features,  Next: Library Catalogs,  Prev: Feature,  Up: The Library System
  74. Requesting Features
  75. ===================
  76. SLIB creates and maintains a "catalog" mapping features to locations of
  77. files introducing procedures and syntax denoted by those features.
  78. At the beginning of each section of this manual, there is a line like
  79. `(require 'FEATURE)'.  The Scheme files comprising SLIB are cataloged
  80. so that these feature names map to the corresponding files.
  81. SLIB provides a form, `require', which loads the files providing the
  82. requested feature.
  83.  - Procedure: require FEATURE
  84.         * If `(provided? FEATURE)' is true, then `require' just returns
  85.           an unspecified value.
  86.         * Otherwise, if FEATURE is found in the catalog, then the
  87.           corresponding files will be loaded and an unspecified value
  88.           returned.
  89.           Subsequently `(provided? FEATURE)' will return `#t'.
  90.         * Otherwise (FEATURE not found in the catalog), an error is
  91.           signaled.
  92. The catalog can also be queried using `require:feature->path'.
  93.  - Function: require:feature->path FEATURE
  94.         * If FEATURE is already provided, then returns `#t'.
  95.         * Otherwise, if FEATURE is in the catalog, the path or list of
  96.           paths associated with FEATURE is returned.
  97.         * Otherwise, returns `#f'.
  98. File: slib.info,  Node: Library Catalogs,  Next: Catalog Compilation,  Prev: Requesting Features,  Up: The Library System
  99. Library Catalogs
  100. ================
  101. At the start of a session no catalog is present, but is created with the
  102. first catalog inquiry (such as `(require 'random)').  Several sources
  103. of catalog information are combined to produce the catalog:
  104.    * standard SLIB packages.
  105.    * additional packages of interest to this site.
  106.    * packages specifically for the variety of Scheme which this session
  107.      is running.
  108.    * packages this user wants to always have available.  This catalog
  109.      is the file `homecat' in the user's "HOME" directory.
  110.    * packages germane to working in this (current working) directory.
  111.      This catalog is the file `usercat' in the directory to which it
  112.      applies.  One would typically `cd' to this directory before
  113.      starting the Scheme session.
  114. Catalog files consist of one or more "association list"s.  In the
  115. circumstance where a feature symbol appears in more than one list, the
  116. latter list's association is retrieved.  Here are the supported formats
  117. for elements of catalog lists:
  118. `(FEATURE . <symbol>)'
  119.      Redirects to the feature named <symbol>.
  120. `(FEATURE . "<path>")'
  121.      Loads file <path>.
  122. `(FEATURE source "<path>")'
  123.      `slib:load's the Scheme source file <path>.
  124. `(FEATURE compiled "<path>" ...)'
  125.      `slib:load-compiled's the files <path> ....
  126. The various macro styles first `require' the named macro package, then
  127. just load <path> or load-and-macro-expand <path> as appropriate for the
  128. implementation.
  129. `(FEATURE defmacro "<path>")'
  130.      `defmacro:load's the Scheme source file <path>.
  131. `(FEATURE macro-by-example "<path>")'
  132.      `defmacro:load's the Scheme source file <path>.
  133. `(FEATURE macro "<path>")'
  134.      `macro:load's the Scheme source file <path>.
  135. `(FEATURE macros-that-work "<path>")'
  136.      `macro:load's the Scheme source file <path>.
  137. `(FEATURE syntax-case "<path>")'
  138.      `macro:load's the Scheme source file <path>.
  139. `(FEATURE syntactic-closures "<path>")'
  140.      `macro:load's the Scheme source file <path>.
  141. Here is an example of a `usercat' catalog.  A Program in this directory
  142. can invoke the `run' feature with `(require 'run)'.
  143.      ;;; "usercat": SLIB catalog additions for SIMSYNCH.     -*-scheme-*-
  144.      
  145.      (
  146.       (simsynch      . "../synch/simsynch.scm")
  147.       (run           . "../synch/run.scm")
  148.       (schlep        . "schlep.scm")
  149.      )
  150. File: slib.info,  Node: Catalog Compilation,  Next: Built-in Support,  Prev: Library Catalogs,  Up: The Library System
  151. Catalog Compilation
  152. ===================
  153. SLIB combines the catalog information which doesn't vary per user into
  154. the file `slibcat' in the implementation-vicinity.  Therefore `slibcat'
  155. needs change only when new software is installed or compiled.  Because
  156. the actual pathnames of files can differ from installation to
  157. installation, SLIB builds a separate catalog for each implementation it
  158. is used with.
  159. The definition of `*SLIB-VERSION*' in SLIB file `require.scm' is
  160. checked against the catalog association of `*SLIB-VERSION*' to
  161. ascertain when versions have changed.  I recommend that the definition
  162. of `*SLIB-VERSION*' be changed whenever the library is changed.  If
  163. multiple implementations of Scheme use SLIB, remember that recompiling
  164. one `slibcat' will fix only that implementation's catalog.
  165. The compilation scripts of Scheme implementations which work with SLIB
  166. can automatically trigger catalog compilation by deleting `slibcat' or
  167. by invoking a special form of `require':
  168.  - Procedure: require 'new-catalog
  169.      This will load `mklibcat', which compiles and writes a new
  170.      `slibcat'.
  171. Another special form of `require' erases SLIB's catalog, forcing it to
  172. be reloaded the next time the catalog is queried.
  173.  - Procedure: require #f
  174.      Removes SLIB's catalog information.  This should be done before
  175.      saving an executable image so that, when restored, its catalog
  176.      will be loaded afresh.
  177. Each file in the table below is descibed in terms of its file-system
  178. independent "vicinity" (*note Vicinity::.).  The entries of a catalog
  179. in the table override those of catalogs above it in the table.
  180. `implementation-vicinity' `slibcat'
  181.      This file contains the associations for the packages comprising
  182.      SLIB, the `implcat' and the `sitecat's.  The associations in the
  183.      other catalogs override those of the standard catalog.
  184. `library-vicinity' `mklibcat.scm'
  185.      creates `slibcat'.
  186. `library-vicinity' `sitecat'
  187.      This file contains the associations specific to an SLIB
  188.      installation.
  189. `implementation-vicinity' `implcat'
  190.      This file contains the associations specific to an implementation
  191.      of Scheme.  Different implementations of Scheme should have
  192.      different `implementation-vicinity'.
  193. `implementation-vicinity' `mkimpcat.scm'
  194.      if present, creates `implcat'.
  195. `implementation-vicinity' `sitecat'
  196.      This file contains the associations specific to a Scheme
  197.      implementation installation.
  198. `home-vicinity' `homecat'
  199.      This file contains the associations specific to an SLIB user.
  200. `user-vicinity' `usercat'
  201.      This file contains associations effecting only those sessions whose
  202.      "working directory" is `user-vicinity'.
  203. File: slib.info,  Node: Built-in Support,  Next: About this manual,  Prev: Catalog Compilation,  Up: The Library System
  204. Built-in Support
  205. ================
  206. The procedures described in these sections are supported by all
  207. implementations as part of the `*.init' files or by `require.scm'.
  208. * Menu:
  209. * Require::                     Module Management
  210. * Vicinity::                    Pathname Management
  211. * Configuration::               Characteristics of Scheme Implementation
  212. * Input/Output::                Things not provided by the Scheme specs.
  213. * Legacy::
  214. * System::                      LOADing, EVALing, ERRORing, and EXITing
  215. File: slib.info,  Node: Require,  Next: Vicinity,  Prev: Built-in Support,  Up: Built-in Support
  216. Require
  217. -------
  218.  - Variable: *features*
  219.      Is a list of symbols denoting features supported in this
  220.      implementation.  *FEATURES* can grow as modules are `require'd.
  221.      *FEATURES* must be defined by all implementations (*note
  222.      Porting::.).
  223.      Here are features which SLIB (`require.scm') adds to *FEATURES*
  224.      when appropriate.
  225.         * 'inexact
  226.         * 'rational
  227.         * 'real
  228.         * 'complex
  229.         * 'bignum
  230.      For each item, `(provided? 'FEATURE)' will return `#t' if that
  231.      feature is available, and `#f' if not.
  232.  - Variable: *modules*
  233.      Is a list of pathnames denoting files which have been loaded.
  234.  - Variable: *catalog*
  235.      Is an association list of features (symbols) and pathnames which
  236.      will supply those features.  The pathname can be either a string
  237.      or a pair.  If pathname is a pair then the first element should be
  238.      a macro feature symbol, `source', or `compiled'.  The cdr of the
  239.      pathname should be either a string or a list.
  240. In the following functions if the argument FEATURE is not a symbol it
  241. is assumed to be a pathname.
  242.  - Function: provided? FEATURE
  243.      Returns `#t' if FEATURE is a member of `*features*' or `*modules*'
  244.      or if FEATURE is supported by a file already loaded and `#f'
  245.      otherwise.
  246.  - Procedure: require FEATURE
  247.      FEATURE is a symbol.  If `(provided? FEATURE)' is true `require'
  248.      returns.  Otherwise, if `(assq FEATURE *catalog*)' is not `#f',
  249.      the associated files will be loaded and `(provided? FEATURE)' will
  250.      henceforth return `#t'.  An unspecified value is returned.  If
  251.      FEATURE is not found in `*catalog*', then an error is signaled.
  252.  - Procedure: require PATHNAME
  253.      PATHNAME is a string.  If PATHNAME has not already been given as
  254.      an argument to `require', PATHNAME is loaded.  An unspecified
  255.      value is returned.
  256.  - Procedure: provide FEATURE
  257.      Assures that FEATURE is contained in `*features*' if FEATURE is a
  258.      symbol and `*modules*' otherwise.
  259.  - Function: require:feature->path FEATURE
  260.      Returns `#t' if FEATURE is a member of `*features*' or `*modules*'
  261.      or if FEATURE is supported by a file already loaded.  Returns a
  262.      path if one was found in `*catalog*' under the feature name, and
  263.      `#f' otherwise.  The path can either be a string suitable as an
  264.      argument to load or a pair as described above for *catalog*.
  265. File: slib.info,  Node: Vicinity,  Next: Configuration,  Prev: Require,  Up: Built-in Support
  266. Vicinity
  267. --------
  268. A vicinity is a descriptor for a place in the file system.  Vicinities
  269. hide from the programmer the concepts of host, volume, directory, and
  270. version.  Vicinities express only the concept of a file environment
  271. where a file name can be resolved to a file in a system independent
  272. manner.  Vicinities can even be used on "flat" file systems (which have
  273. no directory structure) by having the vicinity express constraints on
  274. the file name.  On most systems a vicinity would be a string.  All of
  275. these procedures are file system dependent.
  276. These procedures are provided by all implementations.
  277.  - Function: make-vicinity PATH
  278.      Returns the vicinity of PATH for use by `in-vicinity'.
  279.  - Function: program-vicinity
  280.      Returns the vicinity of the currently loading Scheme code.  For an
  281.      interpreter this would be the directory containing source code.
  282.      For a compiled system (with multiple files) this would be the
  283.      directory where the object or executable files are.  If no file is
  284.      currently loading it the result is undefined.  *Warning:*
  285.      `program-vicinity' can return incorrect values if your program
  286.      escapes back into a `load'.
  287.  - Function: library-vicinity
  288.      Returns the vicinity of the shared Scheme library.
  289.  - Function: implementation-vicinity
  290.      Returns the vicinity of the underlying Scheme implementation.  This
  291.      vicinity will likely contain startup code and messages and a
  292.      compiler.
  293.  - Function: user-vicinity
  294.      Returns the vicinity of the current directory of the user.  On most
  295.      systems this is `""' (the empty string).
  296.  - Function: home-vicinity
  297.      Returns the vicinity of the user's "HOME" directory, the directory
  298.      which typically contains files which customize a computer
  299.      environment for a user.  If scheme is running without a user (eg.
  300.      a daemon) or if this concept is meaningless for the platform, then
  301.      `home-vicinity' returns `#f'.
  302.  - Function: in-vicinity VICINITY FILENAME
  303.      Returns a filename suitable for use by `slib:load',
  304.      `slib:load-source', `slib:load-compiled', `open-input-file',
  305.      `open-output-file', etc.  The returned filename is FILENAME in
  306.      VICINITY.  `in-vicinity' should allow FILENAME to override
  307.      VICINITY when FILENAME is an absolute pathname and VICINITY is
  308.      equal to the value of `(user-vicinity)'.  The behavior of
  309.      `in-vicinity' when FILENAME is absolute and VICINITY is not equal
  310.      to the value of `(user-vicinity)' is unspecified.  For most systems
  311.      `in-vicinity' can be `string-append'.
  312.  - Function: sub-vicinity VICINITY NAME
  313.      Returns the vicinity of VICINITY restricted to NAME.  This is used
  314.      for large systems where names of files in subsystems could
  315.      conflict.  On systems with directory structure `sub-vicinity' will
  316.      return a pathname of the subdirectory NAME of VICINITY.
  317. File: slib.info,  Node: Configuration,  Next: Input/Output,  Prev: Vicinity,  Up: Built-in Support
  318. Configuration
  319. -------------
  320. These constants and procedures describe characteristics of the Scheme
  321. and underlying operating system.  They are provided by all
  322. implementations.
  323.  - Constant: char-code-limit
  324.      An integer 1 larger that the largest value which can be returned by
  325.      `char->integer'.
  326.  - Constant: most-positive-fixnum
  327.      In implementations which support integers of practically unlimited
  328.      size, MOST-POSITIVE-FIXNUM is a large exact integer within the
  329.      range of exact integers that may result from computing the length
  330.      of a list, vector, or string.
  331.      In implementations which do not support integers of practically
  332.      unlimited size, MOST-POSITIVE-FIXNUM is the largest exact integer
  333.      that may result from computing the length of a list, vector, or
  334.      string.
  335.  - Constant: slib:tab
  336.      The tab character.
  337.  - Constant: slib:form-feed
  338.      The form-feed character.
  339.  - Function: software-type
  340.      Returns a symbol denoting the generic operating system type.  For
  341.      instance, `unix', `vms', `macos', `amiga', or `ms-dos'.
  342.  - Function: slib:report-version
  343.      Displays the versions of SLIB and the underlying Scheme
  344.      implementation and the name of the operating system.  An
  345.      unspecified value is returned.
  346.           (slib:report-version) => slib "2c5" on scm "5b1" on unix            |
  347.  - Function: slib:report
  348.      Displays the information of `(slib:report-version)' followed by
  349.      almost all the information neccessary for submitting a problem
  350.      report.  An unspecified value is returned.
  351.  - Function: slib:report #T
  352.      provides a more verbose listing.
  353.  - Function: slib:report FILENAME
  354.      Writes the report to file `filename'.
  355.           (slib:report)
  356.           =>
  357.           slib "2c5" on scm "5b1" on unix                                     |
  358.           (implementation-vicinity) is "/home/jaffer/scm/"
  359.           (library-vicinity) is "/home/jaffer/slib/"
  360.           (scheme-file-suffix) is ".scm"
  361.           loaded *features* :
  362.                   trace alist qp sort
  363.                   common-list-functions macro values getopt
  364.                   compiled
  365.           implementation *features* :
  366.                   bignum complex real rational
  367.                   inexact vicinity ed getenv
  368.                   tmpnam abort transcript with-file
  369.                   ieee-p1178 rev4-report rev4-optional-procedures hash
  370.                   object-hash delay eval dynamic-wind
  371.                   multiarg-apply multiarg/and- logical defmacro
  372.                   string-port source current-time record
  373.                   rev3-procedures rev2-procedures sun-dl string-case
  374.                   array dump char-ready? full-continuation
  375.                   system
  376.           implementation *catalog* :
  377.                   (i/o-extensions compiled "/home/jaffer/scm/ioext.so")
  378.                   ...
  379. File: slib.info,  Node: Input/Output,  Next: Legacy,  Prev: Configuration,  Up: Built-in Support
  380. Input/Output
  381. ------------
  382. These procedures are provided by all implementations.
  383.  - Procedure: file-exists? FILENAME
  384.      Returns `#t' if the specified file exists.  Otherwise, returns
  385.      `#f'.  If the underlying implementation does not support this
  386.      feature then `#f' is always returned.
  387.  - Procedure: delete-file FILENAME
  388.      Deletes the file specified by FILENAME.  If FILENAME can not be
  389.      deleted, `#f' is returned.  Otherwise, `#t' is returned.
  390.  - Procedure: tmpnam
  391.      Returns a pathname for a file which will likely not be used by any
  392.      other process.  Successive calls to `(tmpnam)' will return
  393.      different pathnames.
  394.  - Procedure: current-error-port
  395.      Returns the current port to which diagnostic and error output is
  396.      directed.
  397.  - Procedure: force-output
  398.  - Procedure: force-output PORT
  399.      Forces any pending output on PORT to be delivered to the output
  400.      device and returns an unspecified value.  The PORT argument may be
  401.      omitted, in which case it defaults to the value returned by
  402.      `(current-output-port)'.
  403.  - Procedure: output-port-width
  404.  - Procedure: output-port-width PORT
  405.      Returns the width of PORT, which defaults to
  406.      `(current-output-port)' if absent.  If the width cannot be
  407.      determined 79 is returned.
  408.  - Procedure: output-port-height
  409.  - Procedure: output-port-height PORT
  410.      Returns the height of PORT, which defaults to
  411.      `(current-output-port)' if absent.  If the height cannot be
  412.      determined 24 is returned.
  413. File: slib.info,  Node: Legacy,  Next: System,  Prev: Input/Output,  Up: Built-in Support
  414. Legacy
  415. ------
  416.   These procedures are provided by all implementations.
  417.  - Function: identity X
  418.      IDENTITY returns its argument.
  419.      Example:
  420.           (identity 3)
  421.              => 3
  422.           (identity '(foo bar))
  423.              => (foo bar)
  424.           (map identity LST)
  425.              == (copy-list LST)
  426. The following procedures were present in Scheme until R4RS (*note
  427. Language changes: (r4rs)Notes.).  They are provided by all SLIB
  428. implementations.
  429.  - Constant: t
  430.      Derfined as `#t'.
  431.  - Constant: nil
  432.      Defined as `#f'.
  433.  - Function: last-pair L
  434.      Returns the last pair in the list L.  Example:
  435.           (last-pair (cons 1 2))
  436.              => (1 . 2)
  437.           (last-pair '(1 2))
  438.              => (2)
  439.               == (cons 2 '())
  440. File: slib.info,  Node: System,  Prev: Legacy,  Up: Built-in Support
  441. System
  442. ------
  443. These procedures are provided by all implementations.
  444.  - Procedure: slib:load-source NAME
  445.      Loads a file of Scheme source code from NAME with the default
  446.      filename extension used in SLIB.  For instance if the filename
  447.      extension used in SLIB is `.scm' then `(slib:load-source "foo")'
  448.      will load from file `foo.scm'.
  449.  - Procedure: slib:load-compiled NAME
  450.      On implementations which support separtely loadable compiled
  451.      modules, loads a file of compiled code from NAME with the
  452.      implementation's filename extension for compiled code appended.
  453.  - Procedure: slib:load NAME
  454.      Loads a file of Scheme source or compiled code from NAME with the
  455.      appropriate suffixes appended.  If both source and compiled code
  456.      are present with the appropriate names then the implementation
  457.      will load just one.  It is up to the implementation to choose
  458.      which one will be loaded.
  459.      If an implementation does not support compiled code then
  460.      `slib:load' will be identical to `slib:load-source'.
  461.  - Procedure: slib:eval OBJ
  462.      `eval' returns the value of OBJ evaluated in the current top level
  463.      environment.  *Note Eval:: provides a more general evaluation
  464.      facility.
  465.  - Procedure: slib:eval-load FILENAME EVAL
  466.      FILENAME should be a string.  If filename names an existing file,
  467.      the Scheme source code expressions and definitions are read from
  468.      the file and EVAL called with them sequentially.  The
  469.      `slib:eval-load' procedure does not affect the values returned by
  470.      `current-input-port' and `current-output-port'.
  471.  - Procedure: slib:warn ARG1 ARG2 ...
  472.      Outputs a warning message containing the arguments.
  473.  - Procedure: slib:error ARG1 ARG2 ...
  474.      Outputs an error message containing the arguments, aborts
  475.      evaluation of the current form and responds in a system dependent
  476.      way to the error.  Typical responses are to abort the program or
  477.      to enter a read-eval-print loop.
  478.  - Procedure: slib:exit N
  479.  - Procedure: slib:exit
  480.      Exits from the Scheme session returning status N to the system.
  481.      If N is omitted or `#t', a success status is returned to the
  482.      system (if possible).  If N is `#f' a failure is returned to the
  483.      system (if possible).  If N is an integer, then N is returned to
  484.      the system (if possible).  If the Scheme session cannot exit an
  485.      unspecified value is returned from `slib:exit'.
  486. File: slib.info,  Node: About this manual,  Prev: Built-in Support,  Up: The Library System
  487. About this manual
  488. =================
  489.    * Entries that are labeled as Functions are called for their return
  490.      values.  Entries that are labeled as Procedures are called
  491.      primarily for their side effects.
  492.    * Examples in this text were produced using the `scm' Scheme
  493.      implementation.
  494.    * At the beginning of each section, there is a line that looks like
  495.      `(require 'feature)'.  Include this line in your code prior to
  496.      using the package.
  497. File: slib.info,  Node: Scheme Syntax Extension Packages,  Next: Textual Conversion Packages,  Prev: The Library System,  Up: Top
  498. Scheme Syntax Extension Packages
  499. ********************************
  500. * Menu:
  501. * Defmacro::                    Supported by all implementations
  502. * R4RS Macros::                 'macro
  503. * Macro by Example::            'macro-by-example
  504. * Macros That Work::            'macros-that-work
  505. * Syntactic Closures::          'syntactic-closures
  506. * Syntax-Case Macros::          'syntax-case
  507. Syntax extensions (macros) included with SLIB.  Also *Note Structures::.
  508. * Fluid-Let::                   'fluid-let
  509. * Yasos::                       'yasos, 'oop, 'collect
  510. File: slib.info,  Node: Defmacro,  Next: R4RS Macros,  Prev: Scheme Syntax Extension Packages,  Up: Scheme Syntax Extension Packages
  511. Defmacro
  512. ========
  513.   Defmacros are supported by all implementations.
  514.  - Function: gentemp
  515.      Returns a new (interned) symbol each time it is called.  The symbol
  516.      names are implementation-dependent
  517.           (gentemp) => scm:G0
  518.           (gentemp) => scm:G1
  519.  - Function: defmacro:eval E
  520.      Returns the `slib:eval' of expanding all defmacros in scheme
  521.      expression E.
  522.  - Function: defmacro:load FILENAME
  523.      FILENAME should be a string.  If filename names an existing file,
  524.      the `defmacro:load' procedure reads Scheme source code expressions
  525.      and definitions from the file and evaluates them sequentially.
  526.      These source code expressions and definitions may contain defmacro
  527.      definitions.  The `macro:load' procedure does not affect the values
  528.      returned by `current-input-port' and `current-output-port'.
  529.  - Function: defmacro? SYM
  530.      Returns `#t' if SYM has been defined by `defmacro', `#f' otherwise.
  531.  - Function: macroexpand-1 FORM
  532.  - Function: macroexpand FORM
  533.      If FORM is a macro call, `macroexpand-1' will expand the macro
  534.      call once and return it.  A FORM is considered to be a macro call
  535.      only if it is a cons whose `car' is a symbol for which a `defmacr'
  536.      has been defined.
  537.      `macroexpand' is similar to `macroexpand-1', but repeatedly
  538.      expands FORM until it is no longer a macro call.
  539.  - Macro: defmacro NAME LAMBDA-LIST FORM ...
  540.      When encountered by `defmacro:eval', `defmacro:macroexpand*', or
  541.      `defmacro:load' defines a new macro which will henceforth be
  542.      expanded when encountered by `defmacro:eval',
  543.      `defmacro:macroexpand*', or `defmacro:load'.
  544. Defmacroexpand
  545. --------------
  546.   `(require 'defmacroexpand)'
  547.  - Function: defmacro:expand* E
  548.      Returns the result of expanding all defmacros in scheme expression
  549.      E.
  550. File: slib.info,  Node: R4RS Macros,  Next: Macro by Example,  Prev: Defmacro,  Up: Scheme Syntax Extension Packages
  551. R4RS Macros
  552. ===========
  553.   `(require 'macro)' is the appropriate call if you want R4RS
  554. high-level macros but don't care about the low level implementation.  If
  555. an SLIB R4RS macro implementation is already loaded it will be used.
  556. Otherwise, one of the R4RS macros implemetations is loaded.
  557.   The SLIB R4RS macro implementations support the following uniform
  558. interface:
  559.  - Function: macro:expand SEXPRESSION
  560.      Takes an R4RS expression, macro-expands it, and returns the result
  561.      of the macro expansion.
  562.  - Function: macro:eval SEXPRESSION
  563.      Takes an R4RS expression, macro-expands it, evals the result of the
  564.      macro expansion, and returns the result of the evaluation.
  565.  - Procedure: macro:load FILENAME
  566.      FILENAME should be a string.  If filename names an existing file,
  567.      the `macro:load' procedure reads Scheme source code expressions and
  568.      definitions from the file and evaluates them sequentially.  These
  569.      source code expressions and definitions may contain macro
  570.      definitions.  The `macro:load' procedure does not affect the
  571.      values returned by `current-input-port' and `current-output-port'.
  572. File: slib.info,  Node: Macro by Example,  Next: Macros That Work,  Prev: R4RS Macros,  Up: Scheme Syntax Extension Packages
  573. Macro by Example
  574. ================
  575.   `(require 'macro-by-example)'
  576.   A vanilla implementation of `Macro by Example' (Eugene Kohlbecker,
  577. R4RS) by Dorai Sitaram, (dorai@cs.rice.edu) using `defmacro'.
  578.    * generating hygienic global `define-syntax' Macro-by-Example macros
  579.      *cheaply*.
  580.    * can define macros which use `...'.
  581.    * needn't worry about a lexical variable in a macro definition
  582.      clashing with a variable from the macro use context
  583.    * don't suffer the overhead of redefining the repl if `defmacro'
  584.      natively supported (most implementations)
  585. Caveat
  586. ------
  587.   These macros are not referentially transparent (*note Macros:
  588. (r4rs)Macros.).  Lexically scoped macros (i.e., `let-syntax' and
  589. `letrec-syntax') are not supported.  In any case, the problem of
  590. referential transparency gains poignancy only when `let-syntax' and
  591. `letrec-syntax' are used.  So you will not be courting large-scale
  592. disaster unless you're using system-function names as local variables
  593. with unintuitive bindings that the macro can't use.  However, if you
  594. must have the full `r4rs' macro functionality, look to the more
  595. featureful (but also more expensive) versions of syntax-rules available
  596. in slib *Note Macros That Work::, *Note Syntactic Closures::, and *Note
  597. Syntax-Case Macros::.
  598.  - Macro: define-syntax KEYWORD TRANSFORMER-SPEC
  599.      The KEYWORD is an identifier, and the TRANSFORMER-SPEC should be
  600.      an instance of `syntax-rules'.
  601.      The top-level syntactic environment is extended by binding the
  602.      KEYWORD to the specified transformer.
  603.           (define-syntax let*
  604.             (syntax-rules ()
  605.               ((let* () body1 body2 ...)
  606.                (let () body1 body2 ...))
  607.               ((let* ((name1 val1) (name2 val2) ...)
  608.                  body1 body2 ...)
  609.                (let ((name1 val1))
  610.                  (let* (( name2 val2) ...)
  611.                    body1 body2 ...)))))
  612.  - Macro: syntax-rules LITERALS SYNTAX-RULE ...
  613.      LITERALS is a list of identifiers, and each SYNTAX-RULE should be
  614.      of the form
  615.      `(PATTERN TEMPLATE)'
  616.      where the PATTERN and  TEMPLATE are as in the grammar above.
  617.      An instance of `syntax-rules' produces a new macro transformer by
  618.      specifying a sequence of hygienic rewrite rules.  A use of a macro
  619.      whose keyword is associated with a transformer specified by
  620.      `syntax-rules' is matched against the patterns contained in the
  621.      SYNTAX-RULEs, beginning with the leftmost SYNTAX-RULE.  When a
  622.      match is found, the macro use is trancribed hygienically according
  623.      to the template.
  624.      Each pattern begins with the keyword for the macro.  This keyword
  625.      is not involved in the matching and is not considered a pattern
  626.      variable or literal identifier.
  627. File: slib.info,  Node: Macros That Work,  Next: Syntactic Closures,  Prev: Macro by Example,  Up: Scheme Syntax Extension Packages
  628. Macros That Work
  629. ================
  630.   `(require 'macros-that-work)'
  631.   `Macros That Work' differs from the other R4RS macro implementations
  632. in that it does not expand derived expression types to primitive
  633. expression types.
  634.  - Function: macro:expand EXPRESSION
  635.  - Function: macwork:expand EXPRESSION
  636.      Takes an R4RS expression, macro-expands it, and returns the result
  637.      of the macro expansion.
  638.  - Function: macro:eval EXPRESSION
  639.  - Function: macwork:eval EXPRESSION
  640.      `macro:eval' returns the value of EXPRESSION in the current top
  641.      level environment.  EXPRESSION can contain macro definitions.
  642.      Side effects of EXPRESSION will affect the top level environment.
  643.  - Procedure: macro:load FILENAME
  644.  - Procedure: macwork:load FILENAME
  645.      FILENAME should be a string.  If filename names an existing file,
  646.      the `macro:load' procedure reads Scheme source code expressions and
  647.      definitions from the file and evaluates them sequentially.  These
  648.      source code expressions and definitions may contain macro
  649.      definitions.  The `macro:load' procedure does not affect the
  650.      values returned by `current-input-port' and `current-output-port'.
  651.   References:
  652.   The `Revised^4 Report on the Algorithmic Language Scheme' Clinger and
  653. Rees [editors].  To appear in LISP Pointers.  Also available as a
  654. technical report from the University of Oregon, MIT AI Lab, and Cornell.
  655.             Macros That Work.  Clinger and Rees.  POPL '91.
  656.   The supported syntax differs from the R4RS in that vectors are allowed
  657. as patterns and as templates and are not allowed as pattern or template
  658. data.
  659.      transformer spec  ==>  (syntax-rules literals rules)
  660.      
  661.      rules  ==>  ()
  662.               |  (rule . rules)
  663.      
  664.      rule  ==>  (pattern template)
  665.      
  666.      pattern  ==>  pattern_var      ; a symbol not in literals
  667.                 |  symbol           ; a symbol in literals
  668.                 |  ()
  669.                 |  (pattern . pattern)
  670.                 |  (ellipsis_pattern)
  671.                 |  #(pattern*)                     ; extends R4RS
  672.                 |  #(pattern* ellipsis_pattern)    ; extends R4RS
  673.                 |  pattern_datum
  674.      
  675.      template  ==>  pattern_var
  676.                  |  symbol
  677.                  |  ()
  678.                  |  (template2 . template2)
  679.                  |  #(template*)                   ; extends R4RS
  680.                  |  pattern_datum
  681.      
  682.      template2  ==>  template
  683.                   |  ellipsis_template
  684.      
  685.      pattern_datum  ==>  string                    ; no vector
  686.                       |  character
  687.                       |  boolean
  688.                       |  number
  689.      
  690.      ellipsis_pattern  ==> pattern ...
  691.      
  692.      ellipsis_template  ==>  template ...
  693.      
  694.      pattern_var  ==>  symbol   ; not in literals
  695.      
  696.      literals  ==>  ()
  697.                  |  (symbol . literals)
  698. Definitions
  699. -----------
  700. Scope of an ellipsis
  701.      Within a pattern or template, the scope of an ellipsis (`...') is
  702.      the pattern or template that appears to its left.
  703. Rank of a pattern variable
  704.      The rank of a pattern variable is the number of ellipses within
  705.      whose scope it appears in the pattern.
  706. Rank of a subtemplate
  707.      The rank of a subtemplate is the number of ellipses within whose
  708.      scope it appears in the template.
  709. Template rank of an occurrence of a pattern variable
  710.      The template rank of an occurrence of a pattern variable within a
  711.      template is the rank of that occurrence, viewed as a subtemplate.
  712. Variables bound by a pattern
  713.      The variables bound by a pattern are the pattern variables that
  714.      appear within it.
  715. Referenced variables of a subtemplate
  716.      The referenced variables of a subtemplate are the pattern
  717.      variables that appear within it.
  718. Variables opened by an ellipsis template
  719.      The variables opened by an ellipsis template are the referenced
  720.      pattern variables whose rank is greater than the rank of the
  721.      ellipsis template.
  722. Restrictions
  723. ------------
  724.   No pattern variable appears more than once within a pattern.
  725.   For every occurrence of a pattern variable within a template, the
  726. template rank of the occurrence must be greater than or equal to the
  727. pattern variable's rank.
  728.   Every ellipsis template must open at least one variable.
  729.   For every ellipsis template, the variables opened by an ellipsis
  730. template must all be bound to sequences of the same length.
  731.   The compiled form of a RULE is
  732.      rule  ==>  (pattern template inserted)
  733.      
  734.      pattern  ==>  pattern_var
  735.                 |  symbol
  736.                 |  ()
  737.                 |  (pattern . pattern)
  738.                 |  ellipsis_pattern
  739.                 |  #(pattern)
  740.                 |  pattern_datum
  741.      
  742.      template  ==>  pattern_var
  743.                  |  symbol
  744.                  |  ()
  745.                  |  (template2 . template2)
  746.                  |  #(pattern)
  747.                  |  pattern_datum
  748.      
  749.      template2  ==>  template
  750.                   |  ellipsis_template
  751.      
  752.      pattern_datum  ==>  string
  753.                       |  character
  754.                       |  boolean
  755.                       |  number
  756.      
  757.      pattern_var  ==>  #(V symbol rank)
  758.      
  759.      ellipsis_pattern  ==>  #(E pattern pattern_vars)
  760.      
  761.      ellipsis_template  ==>  #(E template pattern_vars)
  762.      
  763.      inserted  ==>  ()
  764.                  |  (symbol . inserted)
  765.      
  766.      pattern_vars  ==>  ()
  767.                      |  (pattern_var . pattern_vars)
  768.      
  769.      rank  ==>  exact non-negative integer
  770.   where V and E are unforgeable values.
  771.   The pattern variables associated with an ellipsis pattern are the
  772. variables bound by the pattern, and the pattern variables associated
  773. with an ellipsis template are the variables opened by the ellipsis
  774. template.
  775.   If the template contains a big chunk that contains no pattern
  776. variables or inserted identifiers, then the big chunk will be copied
  777. unnecessarily.  That shouldn't matter very often.
  778. File: slib.info,  Node: Syntactic Closures,  Next: Syntax-Case Macros,  Prev: Macros That Work,  Up: Scheme Syntax Extension Packages
  779. Syntactic Closures
  780. ==================
  781.   `(require 'syntactic-closures)'
  782.  - Function: macro:expand EXPRESSION
  783.  - Function: synclo:expand EXPRESSION
  784.      Returns scheme code with the macros and derived expression types of
  785.      EXPRESSION expanded to primitive expression types.
  786.  - Function: macro:eval EXPRESSION
  787.  - Function: synclo:eval EXPRESSION
  788.      `macro:eval' returns the value of EXPRESSION in the current top
  789.      level environment.  EXPRESSION can contain macro definitions.
  790.      Side effects of EXPRESSION will affect the top level environment.
  791.  - Procedure: macro:load FILENAME
  792.  - Procedure: synclo:load FILENAME
  793.      FILENAME should be a string.  If filename names an existing file,
  794.      the `macro:load' procedure reads Scheme source code expressions and
  795.      definitions from the file and evaluates them sequentially.  These
  796.      source code expressions and definitions may contain macro
  797.      definitions.  The `macro:load' procedure does not affect the
  798.      values returned by `current-input-port' and `current-output-port'.
  799. Syntactic Closure Macro Facility
  800. --------------------------------
  801.                   A Syntactic Closures Macro Facility
  802.                             by Chris Hanson
  803.                             9 November 1991
  804.   This document describes "syntactic closures", a low-level macro
  805. facility for the Scheme programming language.  The facility is an
  806. alternative to the low-level macro facility described in the `Revised^4
  807. Report on Scheme.' This document is an addendum to that report.
  808.   The syntactic closures facility extends the BNF rule for TRANSFORMER
  809. SPEC to allow a new keyword that introduces a low-level macro
  810. transformer:
  811.      TRANSFORMER SPEC := (transformer EXPRESSION)
  812.   Additionally, the following procedures are added:
  813.      make-syntactic-closure
  814.      capture-syntactic-environment
  815.      identifier?
  816.      identifier=?
  817.   The description of the facility is divided into three parts.  The
  818. first part defines basic terminology.  The second part describes how
  819. macro transformers are defined.  The third part describes the use of
  820. "identifiers", which extend the syntactic closure mechanism to be
  821. compatible with `syntax-rules'.
  822. Terminology
  823. ...........
  824.   This section defines the concepts and data types used by the syntactic
  825. closures facility.
  826.    * "Forms" are the syntactic entities out of which programs are
  827.      recursively constructed.  A form is any expression, any
  828.      definition, any syntactic keyword, or any syntactic closure.  The
  829.      variable name that appears in a `set!' special form is also a
  830.      form.  Examples of forms:
  831.           17
  832.           #t
  833.           car
  834.           (+ x 4)
  835.           (lambda (x) x)
  836.           (define pi 3.14159)
  837.           if
  838.           define
  839.    * An "alias" is an alternate name for a given symbol.  It can appear
  840.      anywhere in a form that the symbol could be used, and when quoted
  841.      it is replaced by the symbol; however, it does not satisfy the
  842.      predicate `symbol?'.  Macro transformers rarely distinguish
  843.      symbols from aliases, referring to both as identifiers.
  844.    * A "syntactic" environment maps identifiers to their meanings.
  845.      More precisely, it determines whether an identifier is a syntactic
  846.      keyword or a variable.  If it is a keyword, the meaning is an
  847.      interpretation for the form in which that keyword appears.  If it
  848.      is a variable, the meaning identifies which binding of that
  849.      variable is referenced.  In short, syntactic environments contain
  850.      all of the contextual information necessary for interpreting the
  851.      meaning of a particular form.
  852.    * A "syntactic closure" consists of a form, a syntactic environment,
  853.      and a list of identifiers.  All identifiers in the form take their
  854.      meaning from the syntactic environment, except those in the given
  855.      list.  The identifiers in the list are to have their meanings
  856.      determined later.  A syntactic closure may be used in any context
  857.      in which its form could have been used.  Since a syntactic closure
  858.      is also a form, it may not be used in contexts where a form would
  859.      be illegal.  For example, a form may not appear as a clause in the
  860.      cond special form.  A syntactic closure appearing in a quoted
  861.      structure is replaced by its form.
  862. Transformer Definition
  863. ......................
  864.   This section describes the `transformer' special form and the
  865. procedures `make-syntactic-closure' and `capture-syntactic-environment'.
  866.  - Syntax: transformer EXPRESSION
  867.      Syntax: It is an error if this syntax occurs except as a
  868.      TRANSFORMER SPEC.
  869.      Semantics: The EXPRESSION is evaluated in the standard transformer
  870.      environment to yield a macro transformer as described below.  This
  871.      macro transformer is bound to a macro keyword by the special form
  872.      in which the `transformer' expression appears (for example,
  873.      `let-syntax').
  874.      A "macro transformer" is a procedure that takes two arguments, a
  875.      form and a syntactic environment, and returns a new form.  The
  876.      first argument, the "input form", is the form in which the macro
  877.      keyword occurred.  The second argument, the "usage environment",
  878.      is the syntactic environment in which the input form occurred.
  879.      The result of the transformer, the "output form", is automatically
  880.      closed in the "transformer environment", which is the syntactic
  881.      environment in which the `transformer' expression occurred.
  882.      For example, here is a definition of a push macro using
  883.      `syntax-rules':
  884.           (define-syntax  push
  885.             (syntax-rules ()
  886.               ((push item list)
  887.                (set! list (cons item list)))))
  888.      Here is an equivalent definition using `transformer':
  889.           (define-syntax push
  890.             (transformer
  891.              (lambda (exp env)
  892.                (let ((item
  893.                       (make-syntactic-closure env '() (cadr exp)))
  894.                      (list
  895.                       (make-syntactic-closure env '() (caddr exp))))
  896.                  `(set! ,list (cons ,item ,list))))))
  897.      In this example, the identifiers `set!' and `cons' are closed in
  898.      the transformer environment, and thus will not be affected by the
  899.      meanings of those identifiers in the usage environment `env'.
  900.      Some macros may be non-hygienic by design.  For example, the
  901.      following defines a loop macro that implicitly binds `exit' to an
  902.      escape procedure.  The binding of `exit' is intended to capture
  903.      free references to `exit' in the body of the loop, so `exit' must
  904.      be left free when the body is closed:
  905.           (define-syntax loop
  906.             (transformer
  907.              (lambda (exp env)
  908.                (let ((body (cdr exp)))
  909.                  `(call-with-current-continuation
  910.                    (lambda (exit)
  911.                      (let f ()
  912.                        ,@(map (lambda  (exp)
  913.                                  (make-syntactic-closure env '(exit)
  914.                                                          exp))
  915.                                body)
  916.                        (f))))))))
  917.      To assign meanings to the identifiers in a form, use
  918.      `make-syntactic-closure' to close the form in a syntactic
  919.      environment.
  920.  - Function: make-syntactic-closure ENVIRONMENT FREE-NAMES FORM
  921.      ENVIRONMENT must be a syntactic environment, FREE-NAMES must be a
  922.      list of identifiers, and FORM must be a form.
  923.      `make-syntactic-closure' constructs and returns a syntactic closure
  924.      of FORM in ENVIRONMENT, which can be used anywhere that FORM could
  925.      have been used.  All the identifiers used in FORM, except those
  926.      explicitly excepted by FREE-NAMES, obtain their meanings from
  927.      ENVIRONMENT.
  928.      Here is an example where FREE-NAMES is something other than the
  929.      empty list.  It is instructive to compare the use of FREE-NAMES in
  930.      this example with its use in the `loop' example above: the examples
  931.      are similar except for the source of the identifier being left
  932.      free.
  933.           (define-syntax let1
  934.             (transformer
  935.              (lambda (exp env)
  936.                (let ((id (cadr exp))
  937.                      (init (caddr exp))
  938.                      (exp (cadddr exp)))
  939.                  `((lambda (,id)
  940.                      ,(make-syntactic-closure env (list id) exp))
  941.                    ,(make-syntactic-closure env '() init))))))
  942.      `let1' is a simplified version of `let' that only binds a single
  943.      identifier, and whose body consists of a single expression.  When
  944.      the body expression is syntactically closed in its original
  945.      syntactic environment, the identifier that is to be bound by
  946.      `let1' must be left free, so that it can be properly captured by
  947.      the `lambda' in the output form.
  948.      To obtain a syntactic environment other than the usage
  949.      environment, use `capture-syntactic-environment'.
  950.  - Function: capture-syntactic-environment PROCEDURE
  951.      `capture-syntactic-environment' returns a form that will, when
  952.      transformed, call PROCEDURE on the current syntactic environment.
  953.      PROCEDURE should compute and return a new form to be transformed,
  954.      in that same syntactic environment, in place of the form.
  955.      An example will make this clear.  Suppose we wanted to define a
  956.      simple `loop-until' keyword equivalent to
  957.           (define-syntax loop-until
  958.             (syntax-rules ()
  959.               ((loop-until id init test return step)
  960.                (letrec ((loop
  961.                          (lambda (id)
  962.                            (if test return (loop step)))))
  963.                  (loop init)))))
  964.      The following attempt at defining `loop-until' has a subtle bug:
  965.           (define-syntax loop-until
  966.             (transformer
  967.              (lambda (exp env)
  968.                (let ((id (cadr exp))
  969.                      (init (caddr exp))
  970.                      (test (cadddr exp))
  971.                      (return (cadddr (cdr exp)))
  972.                      (step (cadddr (cddr exp)))
  973.                      (close
  974.                       (lambda (exp free)
  975.                         (make-syntactic-closure env free exp))))
  976.                  `(letrec ((loop
  977.                             (lambda (,id)
  978.                               (if ,(close test (list id))
  979.                                   ,(close return (list id))
  980.                                   (loop ,(close step (list id)))))))
  981.                     (loop ,(close init '())))))))
  982.      This definition appears to take all of the proper precautions to
  983.      prevent unintended captures.  It carefully closes the
  984.      subexpressions in their original syntactic environment and it
  985.      leaves the `id' identifier free in the `test', `return', and
  986.      `step' expressions, so that it will be captured by the binding
  987.      introduced by the `lambda' expression.  Unfortunately it uses the
  988.      identifiers `if' and `loop' within that `lambda' expression, so if
  989.      the user of `loop-until' just happens to use, say, `if' for the
  990.      identifier, it will be inadvertently captured.
  991.      The syntactic environment that `if' and `loop' want to be exposed
  992.      to is the one just outside the `lambda' expression: before the
  993.      user's identifier is added to the syntactic environment, but after
  994.      the identifier loop has been added.
  995.      `capture-syntactic-environment' captures exactly that environment
  996.      as follows:
  997.           (define-syntax loop-until
  998.             (transformer
  999.              (lambda (exp env)
  1000.                (let ((id (cadr exp))
  1001.                      (init (caddr exp))
  1002.                      (test (cadddr exp))
  1003.                      (return (cadddr (cdr exp)))
  1004.                      (step (cadddr (cddr exp)))
  1005.                      (close
  1006.                       (lambda (exp free)
  1007.                         (make-syntactic-closure env free exp))))
  1008.                  `(letrec ((loop
  1009.                             ,(capture-syntactic-environment
  1010.                               (lambda (env)
  1011.                                 `(lambda (,id)
  1012.                                    (,(make-syntactic-closure env '() `if)
  1013.                                     ,(close test (list id))
  1014.                                     ,(close return (list id))
  1015.                                     (,(make-syntactic-closure env '()
  1016.                                                               `loop)
  1017.                                      ,(close step (list id)))))))))
  1018.                     (loop ,(close init '())))))))
  1019.      In this case, having captured the desired syntactic environment,
  1020.      it is convenient to construct syntactic closures of the
  1021.      identifiers `if' and the `loop' and use them in the body of the
  1022.      `lambda'.
  1023.      A common use of `capture-syntactic-environment' is to get the
  1024.      transformer environment of a macro transformer:
  1025.           (transformer
  1026.            (lambda (exp env)
  1027.              (capture-syntactic-environment
  1028.               (lambda (transformer-env)
  1029.                 ...))))
  1030. Identifiers
  1031. ...........
  1032.   This section describes the procedures that create and manipulate
  1033. identifiers.  Previous syntactic closure proposals did not have an
  1034. identifier data type - they just used symbols.  The identifier data
  1035. type extends the syntactic closures facility to be compatible with the
  1036. high-level `syntax-rules' facility.
  1037.   As discussed earlier, an identifier is either a symbol or an "alias".
  1038. An alias is implemented as a syntactic closure whose "form" is an
  1039. identifier:
  1040.      (make-syntactic-closure env '() 'a)
  1041.         => an "alias"
  1042.   Aliases are implemented as syntactic closures because they behave just
  1043. like syntactic closures most of the time.  The difference is that an
  1044. alias may be bound to a new value (for example by `lambda' or
  1045. `let-syntax'); other syntactic closures may not be used this way.  If
  1046. an alias is bound, then within the scope of that binding it is looked
  1047. up in the syntactic environment just like any other identifier.
  1048.   Aliases are used in the implementation of the high-level facility
  1049. `syntax-rules'.  A macro transformer created by `syntax-rules' uses a
  1050. template to generate its output form, substituting subforms of the
  1051. input form into the template.  In a syntactic closures implementation,
  1052. all of the symbols in the template are replaced by aliases closed in
  1053. the transformer environment, while the output form itself is closed in
  1054. the usage environment.  This guarantees that the macro transformation
  1055. is hygienic, without requiring the transformer to know the syntactic
  1056. roles of the substituted input subforms.
  1057.  - Function: identifier? OBJECT
  1058.      Returns `#t' if OBJECT is an identifier, otherwise returns `#f'.
  1059.      Examples:
  1060.           (identifier? 'a)
  1061.              => #t
  1062.           (identifier? (make-syntactic-closure env '() 'a))
  1063.              => #t
  1064.           (identifier? "a")
  1065.              => #f
  1066.           (identifier? #\a)
  1067.              => #f
  1068.           (identifier? 97)
  1069.              => #f
  1070.           (identifier? #f)
  1071.              => #f
  1072.           (identifier? '(a))
  1073.              => #f
  1074.           (identifier? '#(a))
  1075.              => #f
  1076.      The predicate `eq?' is used to determine if two identifers are
  1077.      "the same".  Thus `eq?' can be used to compare identifiers exactly
  1078.      as it would be used to compare symbols.  Often, though, it is
  1079.      useful to know whether two identifiers "mean the same thing".  For
  1080.      example, the `cond' macro uses the symbol `else' to identify the
  1081.      final clause in the conditional.  A macro transformer for `cond'
  1082.      cannot just look for the symbol `else', because the `cond' form
  1083.      might be the output of another macro transformer that replaced the
  1084.      symbol `else' with an alias.  Instead the transformer must look
  1085.      for an identifier that "means the same thing" in the usage
  1086.      environment as the symbol `else' means in the transformer
  1087.      environment.
  1088.  - Function: identifier=? ENVIRONMENT1 IDENTIFIER1 ENVIRONMENT2
  1089.           IDENTIFIER2
  1090.      ENVIRONMENT1 and ENVIRONMENT2 must be syntactic environments, and
  1091.      IDENTIFIER1 and IDENTIFIER2 must be identifiers.  `identifier=?'
  1092.      returns `#t' if the meaning of IDENTIFIER1 in ENVIRONMENT1 is the
  1093.      same as that of IDENTIFIER2 in ENVIRONMENT2, otherwise it returns
  1094.      `#f'.  Examples:
  1095.           (let-syntax
  1096.               ((foo
  1097.                 (transformer
  1098.                  (lambda (form env)
  1099.                    (capture-syntactic-environment
  1100.                     (lambda (transformer-env)
  1101.                       (identifier=? transformer-env 'x env 'x)))))))
  1102.             (list (foo)
  1103.                   (let ((x 3))
  1104.                     (foo))))
  1105.              => (#t #f)
  1106.           (let-syntax ((bar foo))
  1107.             (let-syntax
  1108.                 ((foo
  1109.                   (transformer
  1110.                    (lambda (form env)
  1111.                      (capture-syntactic-environment
  1112.                       (lambda (transformer-env)
  1113.                         (identifier=? transformer-env 'foo
  1114.                                       env (cadr form))))))))
  1115.               (list (foo foo)
  1116.                     (foobar))))
  1117.              => (#f #t)
  1118. Acknowledgements
  1119. ................
  1120.   The syntactic closures facility was invented by Alan Bawden and
  1121. Jonathan Rees.  The use of aliases to implement `syntax-rules' was
  1122. invented by Alan Bawden (who prefers to call them "synthetic names").
  1123. Much of this proposal is derived from an earlier proposal by Alan
  1124. Bawden.
  1125. File: slib.info,  Node: Syntax-Case Macros,  Next: Fluid-Let,  Prev: Syntactic Closures,  Up: Scheme Syntax Extension Packages
  1126. Syntax-Case Macros
  1127. ==================
  1128.   `(require 'syntax-case)'
  1129.  - Function: macro:expand EXPRESSION
  1130.  - Function: syncase:expand EXPRESSION
  1131.      Returns scheme code with the macros and derived expression types of
  1132.      EXPRESSION expanded to primitive expression types.
  1133.  - Function: macro:eval EXPRESSION
  1134.  - Function: syncase:eval EXPRESSION
  1135.      `macro:eval' returns the value of EXPRESSION in the current top
  1136.      level environment.  EXPRESSION can contain macro definitions.
  1137.      Side effects of EXPRESSION will affect the top level environment.
  1138.  - Procedure: macro:load FILENAME
  1139.  - Procedure: syncase:load FILENAME
  1140.      FILENAME should be a string.  If filename names an existing file,
  1141.      the `macro:load' procedure reads Scheme source code expressions and
  1142.      definitions from the file and evaluates them sequentially.  These
  1143.      source code expressions and definitions may contain macro
  1144.      definitions.  The `macro:load' procedure does not affect the
  1145.      values returned by `current-input-port' and `current-output-port'.
  1146.   This is version 2.1 of `syntax-case', the low-level macro facility
  1147. proposed and implemented by Robert Hieb and R. Kent Dybvig.
  1148.   This version is further adapted by Harald Hanche-Olsen
  1149. <hanche@imf.unit.no> to make it compatible with, and easily usable
  1150. with, SLIB.  Mainly, these adaptations consisted of:
  1151.    * Removing white space from `expand.pp' to save space in the
  1152.      distribution.  This file is not meant for human readers anyway...
  1153.    * Removed a couple of Chez scheme dependencies.
  1154.    * Renamed global variables used to minimize the possibility of name
  1155.      conflicts.
  1156.    * Adding an SLIB-specific initialization file.
  1157.    * Removing a couple extra files, most notably the documentation (but
  1158.      see below).
  1159.   If you wish, you can see exactly what changes were done by reading the
  1160. shell script in the file `syncase.sh'.
  1161.   The two PostScript files were omitted in order to not burden the SLIB
  1162. distribution with them.  If you do intend to use `syntax-case',
  1163. however, you should get these files and print them out on a PostScript
  1164. printer.  They are available with the original `syntax-case'
  1165. distribution by anonymous FTP in
  1166. `cs.indiana.edu:/pub/scheme/syntax-case'.
  1167.   In order to use syntax-case from an interactive top level, execute:
  1168.      (require 'syntax-case)
  1169.      (require 'repl)
  1170.      (repl:top-level macro:eval)
  1171.   See the section Repl (*Note Repl::) for more information.
  1172.   To check operation of syntax-case get
  1173. `cs.indiana.edu:/pub/scheme/syntax-case', and type
  1174.      (require 'syntax-case)
  1175.      (syncase:sanity-check)
  1176.   Beware that `syntax-case' takes a long time to load - about 20s on a
  1177. SPARCstation SLC (with SCM) and about 90s on a Macintosh SE/30 (with
  1178. Gambit).
  1179. Notes
  1180. -----
  1181.   All R4RS syntactic forms are defined, including `delay'.  Along with
  1182. `delay' are simple definitions for `make-promise' (into which `delay'
  1183. expressions expand) and `force'.
  1184.   `syntax-rules' and `with-syntax' (described in `TR356') are defined.
  1185.   `syntax-case' is actually defined as a macro that expands into calls
  1186. to the procedure `syntax-dispatch' and the core form `syntax-lambda';
  1187. do not redefine these names.
  1188.   Several other top-level bindings not documented in TR356 are created:
  1189.    * the "hooks" in `hooks.ss'
  1190.    * the `build-' procedures in `output.ss'
  1191.    * `expand-syntax' (the expander)
  1192.   The syntax of define has been extended to allow `(define ID)', which
  1193. assigns ID to some unspecified value.
  1194.   We have attempted to maintain R4RS compatibility where possible.  The
  1195. incompatibilities should be confined to `hooks.ss'.  Please let us know
  1196. if there is some incompatibility that is not flagged as such.
  1197.   Send bug reports, comments, suggestions, and questions to Kent Dybvig
  1198. (dyb@iuvax.cs.indiana.edu).
  1199. Note from maintainer
  1200. --------------------
  1201.   Included with the `syntax-case' files was `structure.scm' which
  1202. defines a macro `define-structure'.  There is no documentation for this
  1203. macro and it is not used by any code in SLIB.
  1204. File: slib.info,  Node: Fluid-Let,  Next: Yasos,  Prev: Syntax-Case Macros,  Up: Scheme Syntax Extension Packages
  1205. Fluid-Let
  1206. =========
  1207.   `(require 'fluid-let)'
  1208.  - Syntax: fluid-let `(BINDINGS ...)' FORMS...
  1209.      (fluid-let ((VARIABLE INIT) ...)
  1210.         EXPRESSION EXPRESSION ...)
  1211.   The INITs are evaluated in the current environment (in some
  1212. unspecified order), the current values of the VARIABLEs are saved, the
  1213. results are assigned to the VARIABLEs, the EXPRESSIONs are evaluated
  1214. sequentially in the current environment, the VARIABLEs are restored to
  1215. their original values, and the value of the last EXPRESSION is returned.
  1216.   The syntax of this special form is similar to that of `let', but
  1217. `fluid-let' temporarily rebinds existing VARIABLEs.  Unlike `let',
  1218. `fluid-let' creates no new bindings; instead it *assigns* the values of
  1219. each INIT to the binding (determined by the rules of lexical scoping)
  1220. of its corresponding VARIABLE.
  1221. File: slib.info,  Node: Yasos,  Prev: Fluid-Let,  Up: Scheme Syntax Extension Packages
  1222. Yasos
  1223. =====
  1224.   `(require 'oop)' or `(require 'yasos)'
  1225.   `Yet Another Scheme Object System' is a simple object system for
  1226. Scheme based on the paper by Norman Adams and Jonathan Rees: `Object
  1227. Oriented Programming in Scheme', Proceedings of the 1988 ACM Conference
  1228. on LISP and Functional Programming, July 1988 [ACM #552880].
  1229.   Another reference is:
  1230.   Ken Dickey.  Scheming with Objects `AI Expert' Volume 7, Number 10
  1231. (October 1992), pp. 24-33.
  1232. * Menu:
  1233. * Yasos terms::                 Definitions and disclaimer.
  1234. * Yasos interface::             The Yasos macros and procedures.
  1235. * Setters::                     Dylan-like setters in Yasos.
  1236. * Yasos examples::              Usage of Yasos and setters.
  1237. File: slib.info,  Node: Yasos terms,  Next: Yasos interface,  Prev: Yasos,  Up: Yasos
  1238. Terms
  1239. -----
  1240. "Object"
  1241.      Any Scheme data object.
  1242. "Instance"
  1243.      An instance of the OO system; an "object".
  1244. "Operation"
  1245.      A METHOD.
  1246. *Notes:*
  1247.      The object system supports multiple inheritance.  An instance can
  1248.      inherit from 0 or more ancestors.  In the case of multiple
  1249.      inherited operations with the same identity, the operation used is
  1250.      that from the first ancestor which contains it (in the ancestor
  1251.      `let').  An operation may be applied to any Scheme data
  1252.      object--not just instances.  As code which creates instances is
  1253.      just code, there are no "classes" and no meta-ANYTHING.  Method
  1254.      dispatch is by a procedure call a la CLOS rather than by `send'
  1255.      syntax a la Smalltalk.
  1256. *Disclaimer:*
  1257.      There are a number of optimizations which can be made.  This
  1258.      implementation is expository (although performance should be quite
  1259.      reasonable).  See the L&FP paper for some suggestions.
  1260. File: slib.info,  Node: Yasos interface,  Next: Setters,  Prev: Yasos terms,  Up: Yasos
  1261. Interface
  1262. ---------
  1263.  - Syntax: define-operation `('OPNAME SELF ARG ...`)' DEFAULT-BODY
  1264.      Defines a default behavior for data objects which don't handle the
  1265.      operation OPNAME.  The default behavior (for an empty
  1266.      DEFAULT-BODY) is to generate an error.
  1267.  - Syntax: define-predicate OPNAME?
  1268.      Defines a predicate OPNAME?, usually used for determining the
  1269.      "type" of an object, such that `(OPNAME? OBJECT)' returns `#t' if
  1270.      OBJECT has an operation OPNAME? and `#f' otherwise.
  1271.  - Syntax: object `((NAME SELF ARG ...) BODY)' ...
  1272.      Returns an object (an instance of the object system) with
  1273.      operations.  Invoking `(NAME OBJECT ARG ...' executes the BODY of
  1274.      the OBJECT with SELF bound to OBJECT and with argument(s) ARG....
  1275.  - Syntax: object-with-ancestors `(('ANCESTOR1 INIT1`)' ...`)'
  1276.           OPERATION ...
  1277.      A `let'-like form of `object' for multiple inheritance.  It
  1278.      returns an object inheriting the behaviour of ANCESTOR1 etc.  An
  1279.      operation will be invoked in an ancestor if the object itself does
  1280.      not provide such a method.  In the case of multiple inherited
  1281.      operations with the same identity, the operation used is the one
  1282.      found in the first ancestor in the ancestor list.
  1283.  - Syntax: operate-as COMPONENT OPERATION SELF ARG ...
  1284.      Used in an operation definition (of SELF) to invoke the OPERATION
  1285.      in an ancestor COMPONENT but maintain the object's identity.  Also
  1286.      known as "send-to-super".
  1287.  - Procedure: print OBJ PORT
  1288.      A default `print' operation is provided which is just `(format
  1289.      PORT OBJ)' (*Note Format::) for non-instances and prints OBJ
  1290.      preceded by `#<INSTANCE>' for instances.
  1291.  - Function: size OBJ
  1292.      The default method returns the number of elements in OBJ if it is
  1293.      a vector, string or list, `2' for a pair, `1' for a character and
  1294.      by default id an error otherwise.  Objects such as collections
  1295.      (*Note Collections::) may override the default in an obvious way.
  1296. File: slib.info,  Node: Setters,  Next: Yasos examples,  Prev: Yasos interface,  Up: Yasos
  1297. Setters
  1298. -------
  1299.   "Setters" implement "generalized locations" for objects associated
  1300. with some sort of mutable state.  A "getter" operation retrieves a
  1301. value from a generalized location and the corresponding setter
  1302. operation stores a value into the location.  Only the getter is named -
  1303. the setter is specified by a procedure call as below.  (Dylan uses
  1304. special syntax.)  Typically, but not necessarily, getters are access
  1305. operations to extract values from Yasos objects (*Note Yasos::).
  1306. Several setters are predefined, corresponding to getters `car', `cdr',
  1307. `string-ref' and `vector-ref' e.g., `(setter car)' is equivalent to
  1308. `set-car!'.
  1309.   This implementation of setters is similar to that in Dylan(TM)
  1310. (`Dylan: An object-oriented dynamic language', Apple Computer Eastern
  1311. Research and Technology).  Common LISP provides similar facilities
  1312. through `setf'.
  1313.  - Function: setter GETTER
  1314.      Returns the setter for the procedure GETTER.  E.g., since
  1315.      `string-ref' is the getter corresponding to a setter which is
  1316.      actually `string-set!':
  1317.           (define foo "foo")
  1318.           ((setter string-ref) foo 0 #\F) ; set element 0 of foo
  1319.           foo => "Foo"
  1320.  - Syntax: set PLACE NEW-VALUE
  1321.      If PLACE is a variable name, `set' is equivalent to `set!'.
  1322.      Otherwise, PLACE must have the form of a procedure call, where the
  1323.      procedure name refers to a getter and the call indicates an
  1324.      accessible generalized location, i.e., the call would return a
  1325.      value.  The return value of `set' is usually unspecified unless
  1326.      used with a setter whose definition guarantees to return a useful
  1327.      value.
  1328.           (set (string-ref foo 2) #\O)  ; generalized location with getter
  1329.           foo => "FoO"
  1330.           (set foo "foo")               ; like set!
  1331.           foo => "foo"
  1332.  - Procedure: add-setter GETTER SETTER
  1333.      Add procedures GETTER and SETTER to the (inaccessible) list of
  1334.      valid setter/getter pairs.  SETTER implements the store operation
  1335.      corresponding to the GETTER access operation for the relevant
  1336.      state.  The return value is unspecified.
  1337.  - Procedure: remove-setter-for GETTER
  1338.      Removes the setter corresponding to the specified GETTER from the
  1339.      list of valid setters.  The return value is unspecified.
  1340.  - Syntax: define-access-operation GETTER-NAME
  1341.      Shorthand for a Yasos `define-operation' defining an operation
  1342.      GETTER-NAME that objects may support to return the value of some
  1343.      mutable state.  The default operation is to signal an error.  The
  1344.      return value is unspecified.
  1345. File: slib.info,  Node: Yasos examples,  Prev: Setters,  Up: Yasos
  1346. Examples
  1347. --------
  1348.      ;;; These definitions for PRINT and SIZE are                             |
  1349.      ;;; already supplied by                                                  |
  1350.      (require 'yasos)
  1351.      
  1352.      (define-operation (print obj port)
  1353.        (format port
  1354.                (if (instance? obj) "#<instance>" "~s")
  1355.                obj))
  1356.      
  1357.      (define-operation (size obj)
  1358.        (cond
  1359.         ((vector? obj) (vector-length obj))
  1360.         ((list?   obj) (length obj))
  1361.         ((pair?   obj) 2)
  1362.         ((string? obj) (string-length obj))
  1363.         ((char?   obj) 1)
  1364.         (else
  1365.          (error "Operation not supported: size" obj))))
  1366.      
  1367.      (define-predicate cell?)
  1368.      (define-operation (fetch obj))
  1369.      (define-operation (store! obj newValue))
  1370.      
  1371.      (define (make-cell value)
  1372.        (object
  1373.         ((cell? self) #t)
  1374.         ((fetch self) value)
  1375.         ((store! self newValue)
  1376.          (set! value newValue)
  1377.          newValue)
  1378.         ((size self) 1)
  1379.         ((print self port)
  1380.          (format port "#<Cell: ~s>" (fetch self)))))
  1381.      
  1382.      (define-operation (discard obj value)
  1383.        (format #t "Discarding ~s~%" value))
  1384.      
  1385.      (define (make-filtered-cell value filter)
  1386.        (object-with-ancestors                                                 |
  1387.         ((cell (make-cell value)))                                            |
  1388.         ((store! self newValue)
  1389.         (if (filter newValue)
  1390.             (store! cell newValue)
  1391.             (discard self newValue)))))
  1392.      
  1393.      (define-predicate array?)
  1394.      (define-operation (array-ref array index))
  1395.      (define-operation (array-set! array index value))
  1396.      
  1397.      (define (make-array num-slots)
  1398.        (let ((anArray (make-vector num-slots)))
  1399.          (object
  1400.           ((array? self) #t)
  1401.           ((size self) num-slots)
  1402.           ((array-ref self index)                                             |
  1403.            (vector-ref  anArray index))                                       |
  1404.           ((array-set! self index newValue)                                   |
  1405.            (vector-set! anArray index newValue))                              |
  1406.           ((print self port)                                                  |
  1407.            (format port "#<Array ~s>" (size self))))))                        |
  1408.      
  1409.      (define-operation (position obj))
  1410.      (define-operation (discarded-value obj))
  1411.      
  1412.      (define (make-cell-with-history value filter size)
  1413.        (let ((pos 0) (most-recent-discard #f))
  1414.          (object-with-ancestors
  1415.           ((cell (make-filtered-call value filter))
  1416.            (sequence (make-array size)))
  1417.           ((array? self) #f)
  1418.           ((position self) pos)
  1419.           ((store! self newValue)
  1420.            (operate-as cell store! self newValue)
  1421.            (array-set! self pos newValue)
  1422.            (set! pos (+ pos 1)))
  1423.           ((discard self value)
  1424.            (set! most-recent-discard value))
  1425.           ((discarded-value self) most-recent-discard)
  1426.           ((print self port)
  1427.            (format port "#<Cell-with-history ~s>"                             |
  1428.                    (fetch self))))))                                          |
  1429.      
  1430.      (define-access-operation fetch)
  1431.      (add-setter fetch store!)
  1432.      (define foo (make-cell 1))
  1433.      (print foo #f)
  1434.      => "#<Cell: 1>"
  1435.      (set (fetch foo) 2)
  1436.      =>
  1437.      (print foo #f)
  1438.      => "#<Cell: 2>"
  1439.      (fetch foo)
  1440.      => 2
  1441. File: slib.info,  Node: Textual Conversion Packages,  Next: Mathematical Packages,  Prev: Scheme Syntax Extension Packages,  Up: Top
  1442. Textual Conversion Packages
  1443. ***************************
  1444. * Menu:
  1445. * Precedence Parsing::
  1446. * Format::                      Common-Lisp Format
  1447. * Standard Formatted I/O::      Posix printf and scanf
  1448. * Programs and Arguments::
  1449. * HTML HTTP and CGI::           Generate pages and serve WWW sites
  1450. * Printing Scheme::             Nicely
  1451. * Time and Date::
  1452. * Vector Graphics::
  1453. * Schmooz::                     Documentation markup for Scheme programs
  1454. File: slib.info,  Node: Precedence Parsing,  Next: Format,  Prev: Textual Conversion Packages,  Up: Textual Conversion Packages
  1455. Precedence Parsing
  1456. ==================
  1457.   `(require 'precedence-parse)' or `(require 'parse)'
  1458. This package implements:
  1459.    * a Pratt style precedence parser;
  1460.    * a "tokenizer" which congeals tokens according to assigned classes
  1461.      of constituent characters;
  1462.    * procedures giving direct control of parser rulesets;
  1463.    * procedures for higher level specification of rulesets.
  1464. * Menu:
  1465. * Precedence Parsing Overview::
  1466. * Ruleset Definition and Use::
  1467. * Token definition::
  1468. * Nud and Led Definition::
  1469. * Grammar Rule Definition::
  1470. File: slib.info,  Node: Precedence Parsing Overview,  Next: Ruleset Definition and Use,  Prev: Precedence Parsing,  Up: Precedence Parsing
  1471. Precedence Parsing Overview
  1472. ---------------------------
  1473. This package offers improvements over previous parsers.
  1474.    * Common computer language constructs are concisely specified.
  1475.    * Grammars can be changed dynamically.  Operators can be assigned
  1476.      different meanings within a lexical context.
  1477.    * Rulesets don't need compilation.  Grammars can be changed
  1478.      incrementally.
  1479.    * Operator precedence is specified by integers.
  1480.    * All possibilities of bad input are handled (1) and return as much
  1481.      structure as was parsed when the error occured; The symbol `?' is
  1482.      substituted for missing input.
  1483. Here are the higher-level syntax types and an example of each.
  1484. Precedence considerations are omitted for clarity.  *Note Grammar Rule
  1485. Definition:: for full details.
  1486.  - Grammar: nofix bye exit
  1487.           bye
  1488.      calls the function `exit' with no arguments.
  1489.  - Grammar: prefix - negate
  1490.           - 42
  1491.      Calls the function `negate' with the argument `42'.
  1492.  - Grammar: infix - difference
  1493.           x - y
  1494.      Calls the function `difference' with arguments `x' and `y'.
  1495.  - Grammar: nary + sum
  1496.           x + y + z
  1497.      Calls the function `sum' with arguments `x', `y', and `y'.
  1498.  - Grammar: postfix ! factorial
  1499.           5 !
  1500.      Calls the function `factorial' with the argument `5'.
  1501.  - Grammar: prestfix set set!
  1502.           set foo bar
  1503.      Calls the function `set!' with the arguments `foo' and `bar'.
  1504.  - Grammar: commentfix /* */
  1505.           /* almost any text here */
  1506.      Ignores the comment delimited by `/*' and `*/'.
  1507.  - Grammar: matchfix { list }
  1508.           {0, 1, 2}
  1509.      Calls the function `list' with the arguments `0', `1', and `2'.
  1510.  - Grammar: inmatchfix ( funcall )
  1511.           f(x, y)
  1512.      Calls the function `funcall' with the arguments `f', `x', and `y'.
  1513.  - Grammar: delim ;
  1514.           set foo bar;
  1515.      delimits the extent of the restfix operator `set'.
  1516.   ---------- Footnotes ----------
  1517.   (1) How do I know this?  I parsed 250kbyte of random input (an e-mail
  1518. file) with a non-trivial grammar utilizing all constructs.
  1519. File: slib.info,  Node: Ruleset Definition and Use,  Next: Token definition,  Prev: Precedence Parsing Overview,  Up: Precedence Parsing
  1520. Ruleset Definition and Use
  1521. --------------------------
  1522.  - Variable: *syn-defs*
  1523.      A grammar is built by one or more calls to `prec:define-grammar'.
  1524.      The rules are appended to *SYN-DEFS*.  The value of *SYN-DEFS* is
  1525.      the grammar suitable for passing as an argument to `prec:parse'.
  1526.  - Constant: *syn-ignore-whitespace*
  1527.      Is a nearly empty grammar with whitespace characters set to group
  1528.      0, which means they will not be made into tokens.  Most rulesets
  1529.      will want to start with `*syn-ignore-whitespace*'
  1530. In order to start defining a grammar, either
  1531.      (set! *syn-defs* '())
  1532.      (set! *syn-defs* *syn-ignore-whitespace*)
  1533.  - Function: prec:define-grammar RULE1 ...
  1534.      Appends RULE1 ... to *SYN-DEFS*.  `prec:define-grammar' is used to
  1535.      define both the character classes and rules for tokens.
  1536. Once your grammar is defined, save the value of `*syn-defs*' in a
  1537. variable (for use when calling `prec:parse').
  1538.      (define my-ruleset *syn-defs*)
  1539.  - Function: prec:parse RULESET DELIM
  1540.  - Function: prec:parse RULESET DELIM PORT
  1541.      The RULESET argument must be a list of rules as constructed by
  1542.      `prec:define-grammar' and extracted from *SYN-DEFS*.
  1543.      The token DELIM may be a character, symbol, or string.  A
  1544.      character DELIM argument will match only a character token; i.e. a
  1545.      character for which no token-group is assigned.  A symbols or
  1546.      string will match only a token string; i.e. a token resulting from
  1547.      a token group.
  1548.      `prec:parse' reads a RULESET grammar expression delimited by DELIM
  1549.      from the given input PORT.  `prec:parse' returns the next object
  1550.      parsable from the given input PORT, updating PORT to point to the
  1551.      first character past the end of the external representation of the
  1552.      object.
  1553.      If an end of file is encountered in the input before any
  1554.      characters are found that can begin an object, then an end of file
  1555.      object is returned.  If a delimiter (such as DELIM) is found
  1556.      before any characters are found that can begin an object, then
  1557.      `#f' is returned.
  1558.      The PORT argument may be omitted, in which case it defaults to the
  1559.      value returned by `current-input-port'.  It is an error to parse
  1560.      from a closed port.
  1561. File: slib.info,  Node: Token definition,  Next: Nud and Led Definition,  Prev: Ruleset Definition and Use,  Up: Precedence Parsing
  1562. Token definition
  1563. ----------------
  1564.  - Function: tok:char-group GROUP CHARS CHARS-PROC
  1565.      The argument CHARS may be a single character, a list of
  1566.      characters, or a string.  Each character in CHARS is treated as
  1567.      though `tok:char-group' was called with that character alone.
  1568.      The argument CHARS-PROC must be a procedure of one argument, a
  1569.      list of characters.  After `tokenize' has finished accumulating
  1570.      the characters for a token, it calls CHARS-PROC with the list of
  1571.      characters.  The value returned is the token which `tokenize'
  1572.      returns.
  1573.      The argument GROUP may be an exact integer or a procedure of one
  1574.      character argument.  The following discussion concerns the
  1575.      treatment which the tokenizing routine, `tokenize', will accord to
  1576.      characters on the basis of their groups.
  1577.      When GROUP is a non-zero integer, characters whose group number is
  1578.      equal to or exactly one less than GROUP will continue to
  1579.      accumulate.  Any other character causes the accumulation to stop
  1580.      (until a new token is to be read).
  1581.      The GROUP of zero is special.  These characters are ignored when
  1582.      parsed pending a token, and stop the accumulation of token
  1583.      characters when the accumulation has already begun.  Whitespace
  1584.      characters are usually put in group 0.
  1585.      If GROUP is a procedure, then, when triggerd by the occurence of
  1586.      an initial (no accumulation) CHARS character, this procedure will
  1587.      be repeatedly called with each successive character from the input
  1588.      stream until the GROUP procedure returns a non-false value.
  1589. The following convenient constants are provided for use with
  1590. `tok:char-group'.
  1591.  - Constant: tok:decimal-digits
  1592.      Is the string `"0123456789"'.
  1593.  - Constant: tok:upper-case
  1594.      Is the string consisting of all upper-case letters
  1595.      ("ABCDEFGHIJKLMNOPQRSTUVWXYZ").
  1596.  - Constant: tok:lower-case
  1597.      Is the string consisting of all lower-case letters
  1598.      ("abcdefghijklmnopqrstuvwxyz").
  1599.  - Constant: tok:whitespaces
  1600.      Is the string consisting of all characters between 0 and 255 for
  1601.      which `char-whitespace?' returns true.
  1602. File: slib.info,  Node: Nud and Led Definition,  Next: Grammar Rule Definition,  Prev: Token definition,  Up: Precedence Parsing
  1603. Nud and Led Definition
  1604. ----------------------
  1605.   This section describes advanced features.  You can skip this section
  1606. on first reading.
  1607. The "Null Denotation" (or "nud") of a token is the procedure and
  1608. arguments applying for that token when "Left", an unclaimed parsed
  1609. expression is not extant.
  1610. The "Left Denotation" (or "led") of a token is the procedure,
  1611. arguments, and lbp applying for that token when there is a "Left", an
  1612. unclaimed parsed expression.
  1613. In his paper,
  1614.      Pratt, V. R.  Top Down Operator Precendence.  `SIGACT/SIGPLAN
  1615.      Symposium on Principles of Programming Languages', Boston, 1973,
  1616.      pages 41-51
  1617.   the "left binding power" (or "lbp") was an independent property of
  1618. tokens.  I think this was done in order to allow tokens with NUDs but
  1619. not LEDs to also be used as delimiters, which was a problem for
  1620. statically defined syntaxes.  It turns out that *dynamically binding*
  1621. NUDs and LEDs allows them independence.
  1622. For the rule-defining procedures that follow, the variable TK may be a
  1623. character, string, or symbol, or a list composed of characters,
  1624. strings, and symbols.  Each element of TK is treated as though the
  1625. procedure were called for each element.
  1626. Character TK arguments will match only character tokens; i.e.
  1627. characters for which no token-group is assigned.  Symbols and strings
  1628. will both match token strings; i.e. tokens resulting from token groups.
  1629.  - Function: prec:make-nud TK SOP ARG1 ...
  1630.      Returns a rule specifying that SOP be called when TK is parsed.
  1631.      If SOP is a procedure, it is called with TK and ARG1 ... as its
  1632.      arguments; the resulting value is incorporated into the expression
  1633.      being built.  Otherwise, `(list SOP ARG1 ...)' is incorporated.
  1634. If no NUD has been defined for a token; then if that token is a string,
  1635. it is converted to a symbol and returned; if not a string, the token is
  1636. returned.
  1637.  - Function: prec:make-led TK SOP ARG1 ...
  1638.      Returns a rule specifying that SOP be called when TK is parsed and
  1639.      LEFT has an unclaimed parsed expression.  If SOP is a procedure,
  1640.      it is called with LEFT, TK, and ARG1 ... as its arguments; the
  1641.      resulting value is incorporated into the expression being built.
  1642.      Otherwise, LEFT is incorporated.
  1643. If no LED has been defined for a token, and LEFT is set, the parser
  1644. issues a warning.
  1645. File: slib.info,  Node: Grammar Rule Definition,  Prev: Nud and Led Definition,  Up: Precedence Parsing
  1646. Grammar Rule Definition
  1647. -----------------------
  1648. Here are procedures for defining rules for the syntax types introduced
  1649. in *Note Precedence Parsing Overview::.
  1650. For the rule-defining procedures that follow, the variable TK may be a
  1651. character, string, or symbol, or a list composed of characters,
  1652. strings, and symbols.  Each element of TK is treated as though the
  1653. procedure were called for each element.
  1654. For procedures prec:delim, ..., prec:prestfix, if the SOP argument is
  1655. `#f', then the token which triggered this rule is converted to a symbol
  1656. and returned.  A false SOP argument to the procedures prec:commentfix,
  1657. prec:matchfix, or prec:inmatchfix has a different meaning.
  1658. Character TK arguments will match only character tokens; i.e.
  1659. characters for which no token-group is assigned.  Symbols and strings
  1660. will both match token strings; i.e. tokens resulting from token groups.
  1661.  - Function: prec:delim TK
  1662.      Returns a rule specifying that TK should not be returned from
  1663.      parsing; i.e. TK's function is purely syntactic.  The end-of-file
  1664.      is always treated as a delimiter.
  1665.  - Function: prec:nofix TK SOP
  1666.      Returns a rule specifying the following actions take place when TK
  1667.      is parsed:
  1668.         * If SOP is a procedure, it is called with no arguments; the
  1669.           resulting value is incorporated into the expression being
  1670.           built.  Otherwise, the list of SOP is incorporated.
  1671.  - Function: prec:prefix TK SOP BP RULE1 ...
  1672.      Returns a rule specifying the following actions take place when TK
  1673.      is parsed:
  1674.         * The rules RULE1 ... augment and, in case of conflict, override
  1675.           rules currently in effect.
  1676.         * `prec:parse1' is called with binding-power BP.
  1677.         * If SOP is a procedure, it is called with the expression
  1678.           returned from `prec:parse1'; the resulting value is
  1679.           incorporated into the expression being built.  Otherwise, the
  1680.           list of SOP and the expression returned from `prec:parse1' is
  1681.           incorporated.
  1682.         * The ruleset in effect before TK was parsed is restored; RULE1
  1683.           ... are forgotten.
  1684.  - Function: prec:infix TK SOP LBP BP RULE1 ...
  1685.      Returns a rule declaring the left-binding-precedence of the token
  1686.      TK is LBP and specifying the following actions take place when TK
  1687.      is parsed:
  1688.         * The rules RULE1 ... augment and, in case of conflict, override
  1689.           rules currently in effect.
  1690.         * One expression is parsed with binding-power LBP.  If instead a
  1691.           delimiter is encountered, a warning is issued.
  1692.         * If SOP is a procedure, it is applied to the list of LEFT and
  1693.           the parsed expression; the resulting value is incorporated
  1694.           into the expression being built.  Otherwise, the list of SOP,
  1695.           the LEFT expression, and the parsed expression is
  1696.           incorporated.
  1697.         * The ruleset in effect before TK was parsed is restored; RULE1
  1698.           ... are forgotten.
  1699.  - Function: prec:nary TK SOP BP
  1700.      Returns a rule declaring the left-binding-precedence of the token
  1701.      TK is BP and specifying the following actions take place when TK
  1702.      is parsed:
  1703.         * Expressions are parsed with binding-power BP as far as they
  1704.           are interleaved with the token TK.
  1705.         * If SOP is a procedure, it is applied to the list of LEFT and
  1706.           the parsed expressions; the resulting value is incorporated
  1707.           into the expression being built.  Otherwise, the list of SOP,
  1708.           the LEFT expression, and the parsed expressions is
  1709.           incorporated.
  1710.  - Function: prec:postfix TK SOP LBP
  1711.      Returns a rule declaring the left-binding-precedence of the token
  1712.      TK is LBP and specifying the following actions take place when TK
  1713.      is parsed:
  1714.         * If SOP is a procedure, it is called with the LEFT expression;
  1715.           the resulting value is incorporated into the expression being
  1716.           built.  Otherwise, the list of SOP and the LEFT expression is
  1717.           incorporated.
  1718.  - Function: prec:prestfix TK SOP BP RULE1 ...
  1719.      Returns a rule specifying the following actions take place when TK
  1720.      is parsed:
  1721.         * The rules RULE1 ... augment and, in case of conflict, override
  1722.           rules currently in effect.
  1723.         * Expressions are parsed with binding-power BP until a
  1724.           delimiter is reached.
  1725.         * If SOP is a procedure, it is applied to the list of parsed
  1726.           expressions; the resulting value is incorporated into the
  1727.           expression being built.  Otherwise, the list of SOP and the
  1728.           parsed expressions is incorporated.
  1729.         * The ruleset in effect before TK was parsed is restored; RULE1
  1730.           ... are forgotten.
  1731.  - Function: prec:commentfix TK STP MATCH RULE1 ...
  1732.      Returns rules specifying the following actions take place when TK
  1733.      is parsed:
  1734.         * The rules RULE1 ... augment and, in case of conflict, override
  1735.           rules currently in effect.
  1736.         * Characters are read until and end-of-file or a sequence of
  1737.           characters is read which matches the *string* MATCH.
  1738.         * If STP is a procedure, it is called with the string of all
  1739.           that was read between the TK and MATCH (exclusive).
  1740.         * The ruleset in effect before TK was parsed is restored; RULE1
  1741.           ... are forgotten.
  1742.      Parsing of commentfix syntax differs from the others in several
  1743.      ways.  It reads directly from input without tokenizing; It calls
  1744.      STP but does not return its value; nay any value.  I added the STP
  1745.      argument so that comment text could be echoed.
  1746.  - Function: prec:matchfix TK SOP SEP MATCH RULE1 ...
  1747.      Returns a rule specifying the following actions take place when TK
  1748.      is parsed:
  1749.         * The rules RULE1 ... augment and, in case of conflict, override
  1750.           rules currently in effect.
  1751.         * A rule declaring the token MATCH a delimiter takes effect.
  1752.         * Expressions are parsed with binding-power `0' until the token
  1753.           MATCH is reached.  If the token SEP does not appear between
  1754.           each pair of expressions parsed, a warning is issued.
  1755.         * If SOP is a procedure, it is applied to the list of parsed
  1756.           expressions; the resulting value is incorporated into the
  1757.           expression being built.  Otherwise, the list of SOP and the
  1758.           parsed expressions is incorporated.
  1759.         * The ruleset in effect before TK was parsed is restored; RULE1
  1760.           ... are forgotten.
  1761.  - Function: prec:inmatchfix TK SOP SEP MATCH LBP RULE1 ...
  1762.      Returns a rule declaring the left-binding-precedence of the token
  1763.      TK is LBP and specifying the following actions take place when TK
  1764.      is parsed:
  1765.         * The rules RULE1 ... augment and, in case of conflict, override
  1766.           rules currently in effect.
  1767.         * A rule declaring the token MATCH a delimiter takes effect.
  1768.         * Expressions are parsed with binding-power `0' until the token
  1769.           MATCH is reached.  If the token SEP does not appear between
  1770.           each pair of expressions parsed, a warning is issued.
  1771.         * If SOP is a procedure, it is applied to the list of LEFT and
  1772.           the parsed expressions; the resulting value is incorporated
  1773.           into the expression being built.  Otherwise, the list of SOP,
  1774.           the LEFT expression, and the parsed expressions is
  1775.           incorporated.
  1776.         * The ruleset in effect before TK was parsed is restored; RULE1
  1777.           ... are forgotten.
  1778. File: slib.info,  Node: Format,  Next: Standard Formatted I/O,  Prev: Precedence Parsing,  Up: Textual Conversion Packages
  1779. Format (version 3.0)
  1780. ====================
  1781.   `(require 'format)'
  1782. * Menu:
  1783. * Format Interface::
  1784. * Format Specification::
  1785. File: slib.info,  Node: Format Interface,  Next: Format Specification,  Prev: Format,  Up: Format
  1786. Format Interface
  1787. ----------------
  1788.  - Function: format DESTINATION FORMAT-STRING . ARGUMENTS
  1789.      An almost complete implementation of Common LISP format description
  1790.      according to the CL reference book `Common LISP' from Guy L.
  1791.      Steele, Digital Press.  Backward compatible to most of the
  1792.      available Scheme format implementations.
  1793.      Returns `#t', `#f' or a string; has side effect of printing
  1794.      according to FORMAT-STRING.  If DESTINATION is `#t', the output is
  1795.      to the current output port and `#t' is returned.  If DESTINATION
  1796.      is `#f', a formatted string is returned as the result of the call.
  1797.      NEW: If DESTINATION is a string, DESTINATION is regarded as the
  1798.      format string; FORMAT-STRING is then the first argument and the
  1799.      output is returned as a string. If DESTINATION is a number, the
  1800.      output is to the current error port if available by the
  1801.      implementation. Otherwise DESTINATION must be an output port and
  1802.      `#t' is returned.
  1803.      FORMAT-STRING must be a string.  In case of a formatting error
  1804.      format returns `#f' and prints a message on the current output or
  1805.      error port.  Characters are output as if the string were output by
  1806.      the `display' function with the exception of those prefixed by a
  1807.      tilde (~).  For a detailed description of the FORMAT-STRING syntax
  1808.      please consult a Common LISP format reference manual.  For a test
  1809.      suite to verify this format implementation load `formatst.scm'.
  1810.      Please send bug reports to `lutzeb@cs.tu-berlin.de'.
  1811.      Note: `format' is not reentrant, i.e. only one `format'-call may
  1812.      be executed at a time.
  1813. File: slib.info,  Node: Format Specification,  Prev: Format Interface,  Up: Format
  1814. Format Specification (Format version 3.0)
  1815. -----------------------------------------
  1816.   Please consult a Common LISP format reference manual for a detailed
  1817. description of the format string syntax.  For a demonstration of the
  1818. implemented directives see `formatst.scm'.
  1819.   This implementation supports directive parameters and modifiers (`:'
  1820. and `@' characters). Multiple parameters must be separated by a comma
  1821. (`,').  Parameters can be numerical parameters (positive or negative),
  1822. character parameters (prefixed by a quote character (`''), variable
  1823. parameters (`v'), number of rest arguments parameter (`#'), empty and
  1824. default parameters.  Directive characters are case independent. The
  1825. general form of a directive is:
  1826. DIRECTIVE ::= ~{DIRECTIVE-PARAMETER,}[:][@]DIRECTIVE-CHARACTER
  1827. DIRECTIVE-PARAMETER ::= [ [-|+]{0-9}+ | 'CHARACTER | v | # ]
  1828. Implemented CL Format Control Directives
  1829. ........................................
  1830.   Documentation syntax: Uppercase characters represent the corresponding
  1831. control directive characters. Lowercase characters represent control
  1832. directive parameter descriptions.
  1833.      Any (print as `display' does).
  1834.     `~@A'
  1835.           left pad.
  1836.     `~MINCOL,COLINC,MINPAD,PADCHARA'
  1837.           full padding.
  1838.      S-expression (print as `write' does).
  1839.     `~@S'
  1840.           left pad.
  1841.     `~MINCOL,COLINC,MINPAD,PADCHARS'
  1842.           full padding.
  1843.      Decimal.
  1844.     `~@D'
  1845.           print number sign always.
  1846.     `~:D'
  1847.           print comma separated.
  1848.     `~MINCOL,PADCHAR,COMMACHARD'
  1849.           padding.
  1850.      Hexadecimal.
  1851.     `~@X'
  1852.           print number sign always.
  1853.     `~:X'
  1854.           print comma separated.
  1855.     `~MINCOL,PADCHAR,COMMACHARX'
  1856.           padding.
  1857.      Octal.
  1858.     `~@O'
  1859.           print number sign always.
  1860.     `~:O'
  1861.           print comma separated.
  1862.     `~MINCOL,PADCHAR,COMMACHARO'
  1863.           padding.
  1864.      Binary.
  1865.     `~@B'
  1866.           print number sign always.
  1867.     `~:B'
  1868.           print comma separated.
  1869.     `~MINCOL,PADCHAR,COMMACHARB'
  1870.           padding.
  1871. `~NR'
  1872.      Radix N.
  1873.     `~N,MINCOL,PADCHAR,COMMACHARR'
  1874.           padding.
  1875. `~@R'
  1876.      print a number as a Roman numeral.
  1877. `~:@R'
  1878.      print a number as an "old fashioned" Roman numeral.
  1879. `~:R'
  1880.      print a number as an ordinal English number.
  1881. `~:@R'
  1882.      print a number as a cardinal English number.
  1883.      Plural.
  1884.     `~@P'
  1885.           prints `y' and `ies'.
  1886.     `~:P'
  1887.           as `~P but jumps 1 argument backward.'
  1888.     `~:@P'
  1889.           as `~@P but jumps 1 argument backward.'
  1890.      Character.
  1891.     `~@C'
  1892.           prints a character as the reader can understand it (i.e. `#\'
  1893.           prefixing).
  1894.     `~:C'
  1895.           prints a character as emacs does (eg. `^C' for ASCII 03).
  1896.      Fixed-format floating-point (prints a flonum like MMM.NNN).
  1897.     `~WIDTH,DIGITS,SCALE,OVERFLOWCHAR,PADCHARF'
  1898.     `~@F'
  1899.           If the number is positive a plus sign is printed.
  1900.      Exponential floating-point (prints a flonum like MMM.NNN`E'EE).
  1901.     `~WIDTH,DIGITS,EXPONENTDIGITS,SCALE,OVERFLOWCHAR,PADCHAR,EXPONENTCHARE'
  1902.     `~@E'
  1903.           If the number is positive a plus sign is printed.
  1904.      General floating-point (prints a flonum either fixed or
  1905.      exponential).
  1906.     `~WIDTH,DIGITS,EXPONENTDIGITS,SCALE,OVERFLOWCHAR,PADCHAR,EXPONENTCHARG'
  1907.     `~@G'
  1908.           If the number is positive a plus sign is printed.
  1909.      Dollars floating-point (prints a flonum in fixed with signs
  1910.      separated).
  1911.     `~DIGITS,SCALE,WIDTH,PADCHAR$'
  1912.     `~@$'
  1913.           If the number is positive a plus sign is printed.
  1914.     `~:@$'
  1915.           A sign is always printed and appears before the padding.
  1916.     `~:$'
  1917.           The sign appears before the padding.
  1918.      Newline.
  1919.     `~N%'
  1920.           print N newlines.
  1921.      print newline if not at the beginning of the output line.
  1922.     `~N&'
  1923.           prints `~&' and then N-1 newlines.
  1924.      Page Separator.
  1925.     `~N|'
  1926.           print N page separators.
  1927.      Tilde.
  1928.     `~N~'
  1929.           print N tildes.
  1930. `~'<newline>
  1931.      Continuation Line.
  1932.     `~:'<newline>
  1933.           newline is ignored, white space left.
  1934.     `~@'<newline>
  1935.           newline is left, white space ignored.
  1936.      Tabulation.
  1937.     `~@T'
  1938.           relative tabulation.
  1939.     `~COLNUM,COLINCT'
  1940.           full tabulation.
  1941.      Indirection (expects indirect arguments as a list).
  1942.     `~@?'
  1943.           extracts indirect arguments from format arguments.
  1944. `~(STR~)'
  1945.      Case conversion (converts by `string-downcase').
  1946.     `~:(STR~)'
  1947.           converts by `string-capitalize'.
  1948.     `~@(STR~)'
  1949.           converts by `string-capitalize-first'.
  1950.     `~:@(STR~)'
  1951.           converts by `string-upcase'.
  1952.      Argument Jumping (jumps 1 argument forward).
  1953.     `~N*'
  1954.           jumps N arguments forward.
  1955.     `~:*'
  1956.           jumps 1 argument backward.
  1957.     `~N:*'
  1958.           jumps N arguments backward.
  1959.     `~@*'
  1960.           jumps to the 0th argument.
  1961.     `~N@*'
  1962.           jumps to the Nth argument (beginning from 0)
  1963. `~[STR0~;STR1~;...~;STRN~]'
  1964.      Conditional Expression (numerical clause conditional).
  1965.     `~N['
  1966.           take argument from N.
  1967.     `~@['
  1968.           true test conditional.
  1969.     `~:['
  1970.           if-else-then conditional.
  1971.     `~;'
  1972.           clause separator.
  1973.     `~:;'
  1974.           default clause follows.
  1975. `~{STR~}'
  1976.      Iteration (args come from the next argument (a list)).
  1977.     `~N{'
  1978.           at most N iterations.
  1979.     `~:{'
  1980.           args from next arg (a list of lists).
  1981.     `~@{'
  1982.           args from the rest of arguments.
  1983.     `~:@{'
  1984.           args from the rest args (lists).
  1985.      Up and out.
  1986.     `~N^'
  1987.           aborts if N = 0
  1988.     `~N,M^'
  1989.           aborts if N = M
  1990.     `~N,M,K^'
  1991.           aborts if N <= M <= K
  1992. Not Implemented CL Format Control Directives
  1993. ............................................
  1994. `~:A'
  1995.      print `#f' as an empty list (see below).
  1996. `~:S'
  1997.      print `#f' as an empty list (see below).
  1998. `~<~>'
  1999.      Justification.
  2000. `~:^'
  2001.      (sorry I don't understand its semantics completely)
  2002. Extended, Replaced and Additional Control Directives
  2003. ....................................................
  2004. `~MINCOL,PADCHAR,COMMACHAR,COMMAWIDTHD'
  2005. `~MINCOL,PADCHAR,COMMACHAR,COMMAWIDTHX'
  2006. `~MINCOL,PADCHAR,COMMACHAR,COMMAWIDTHO'
  2007. `~MINCOL,PADCHAR,COMMACHAR,COMMAWIDTHB'
  2008. `~N,MINCOL,PADCHAR,COMMACHAR,COMMAWIDTHR'
  2009.      COMMAWIDTH is the number of characters between two comma
  2010.      characters.
  2011.      print a R4RS complex number as `~F~@Fi' with passed parameters for
  2012.      `~F'.
  2013.      Pretty print formatting of an argument for scheme code lists.
  2014.      Same as `~?.'
  2015.      Flushes the output if format DESTINATION is a port.
  2016.      Print a `#\space' character
  2017.     `~N_'
  2018.           print N `#\space' characters.
  2019.      Print a `#\tab' character
  2020.     `~N/'
  2021.           print N `#\tab' characters.
  2022. `~NC'
  2023.      Takes N as an integer representation for a character. No arguments
  2024.      are consumed. N is converted to a character by `integer->char'.  N
  2025.      must be a positive decimal number.
  2026. `~:S'
  2027.      Print out readproof.  Prints out internal objects represented as
  2028.      `#<...>' as strings `"#<...>"' so that the format output can always
  2029.      be processed by `read'.
  2030. `~:A'
  2031.      Print out readproof.  Prints out internal objects represented as
  2032.      `#<...>' as strings `"#<...>"' so that the format output can always
  2033.      be processed by `read'.
  2034.      Prints information and a copyright notice on the format
  2035.      implementation.
  2036.     `~:Q'
  2037.           prints format version.
  2038. `~F, ~E, ~G, ~$'
  2039.      may also print number strings, i.e. passing a number as a string
  2040.      and format it accordingly.
  2041. Configuration Variables
  2042. .......................
  2043.   Format has some configuration variables at the beginning of
  2044. `format.scm' to suit the systems and users needs. There should be no
  2045. modification necessary for the configuration that comes with SLIB.  If
  2046. modification is desired the variable should be set after the format
  2047. code is loaded. Format detects automatically if the running scheme
  2048. system implements floating point numbers and complex numbers.
  2049. FORMAT:SYMBOL-CASE-CONV
  2050.      Symbols are converted by `symbol->string' so the case type of the
  2051.      printed symbols is implementation dependent.
  2052.      `format:symbol-case-conv' is a one arg closure which is either
  2053.      `#f' (no conversion), `string-upcase', `string-downcase' or
  2054.      `string-capitalize'. (default `#f')
  2055. FORMAT:IOBJ-CASE-CONV
  2056.      As FORMAT:SYMBOL-CASE-CONV but applies for the representation of
  2057.      implementation internal objects. (default `#f')
  2058. FORMAT:EXPCH
  2059.      The character prefixing the exponent value in `~E' printing.
  2060.      (default `#\E')
  2061. Compatibility With Other Format Implementations
  2062. ...............................................
  2063. SLIB format 2.x:
  2064.      See `format.doc'.
  2065. SLIB format 1.4:
  2066.      Downward compatible except for padding support and `~A', `~S',
  2067.      `~P', `~X' uppercase printing.  SLIB format 1.4 uses C-style
  2068.      `printf' padding support which is completely replaced by the CL
  2069.      `format' padding style.
  2070. MIT C-Scheme 7.1:
  2071.      Downward compatible except for `~', which is not documented
  2072.      (ignores all characters inside the format string up to a newline
  2073.      character).  (7.1 implements `~a', `~s', ~NEWLINE, `~~', `~%',
  2074.      numerical and variable parameters and `:/@' modifiers in the CL
  2075.      sense).
  2076. Elk 1.5/2.0:
  2077.      Downward compatible except for `~A' and `~S' which print in
  2078.      uppercase.  (Elk implements `~a', `~s', `~~', and `~%' (no
  2079.      directive parameters or modifiers)).
  2080. Scheme->C 01nov91:
  2081.      Downward compatible except for an optional destination parameter:
  2082.      S2C accepts a format call without a destination which returns a
  2083.      formatted string. This is equivalent to a #f destination in S2C.
  2084.      (S2C implements `~a', `~s', `~c', `~%', and `~~' (no directive
  2085.      parameters or modifiers)).
  2086.   This implementation of format is solely useful in the SLIB context
  2087. because it requires other components provided by SLIB.
  2088. File: slib.info,  Node: Standard Formatted I/O,  Next: Programs and Arguments,  Prev: Format,  Up: Textual Conversion Packages
  2089. Standard Formatted I/O
  2090. ======================
  2091. * Menu:
  2092. * Standard Formatted Output::   'printf
  2093. * Standard Formatted Input::    'scanf
  2094. stdio
  2095. -----
  2096.   `(require 'stdio)'
  2097.   `require's `printf' and `scanf' and additionally defines the symbols:
  2098.  - Variable: stdin
  2099.      Defined to be `(current-input-port)'.
  2100.  - Variable: stdout
  2101.      Defined to be `(current-output-port)'.
  2102.  - Variable: stderr
  2103.      Defined to be `(current-error-port)'.
  2104. File: slib.info,  Node: Standard Formatted Output,  Next: Standard Formatted Input,  Prev: Standard Formatted I/O,  Up: Standard Formatted I/O
  2105. Standard Formatted Output
  2106. -------------------------
  2107.   `(require 'printf)'
  2108.  - Procedure: printf FORMAT ARG1 ...
  2109.  - Procedure: fprintf PORT FORMAT ARG1 ...
  2110.  - Procedure: sprintf STR FORMAT ARG1 ...
  2111.  - Procedure: sprintf #F FORMAT ARG1 ...
  2112.  - Procedure: sprintf K FORMAT ARG1 ...
  2113.      Each function converts, formats, and outputs its ARG1 ...
  2114.      arguments according to the control string FORMAT argument and
  2115.      returns the number of characters output.
  2116.      `printf' sends its output to the port `(current-output-port)'.
  2117.      `fprintf' sends its output to the port PORT.  `sprintf'
  2118.      `string-set!'s locations of the non-constant string argument STR
  2119.      to the output characters.
  2120.      Two extensions of `sprintf' return new strings.  If the first
  2121.      argument is `#f', then the returned string's length is as many
  2122.      characters as specified by the FORMAT and data; if the first
  2123.      argument is a non-negative integer K, then the length of the
  2124.      returned string is also bounded by K.
  2125.      The string FORMAT contains plain characters which are copied to
  2126.      the output stream, and conversion specifications, each of which
  2127.      results in fetching zero or more of the arguments ARG1 ....  The
  2128.      results are undefined if there are an insufficient number of
  2129.      arguments for the format.  If FORMAT is exhausted while some of the
  2130.      ARG1 ... arguments remain unused, the excess ARG1 ... arguments
  2131.      are ignored.
  2132.      The conversion specifications in a format string have the form:
  2133.           % [ FLAGS ] [ WIDTH ] [ . PRECISION ] [ TYPE ] CONVERSION
  2134.      An output conversion specifications consist of an initial `%'
  2135.      character followed in sequence by:
  2136.         * Zero or more "flag characters" that modify the normal
  2137.           behavior of the conversion specification.
  2138.          `-'
  2139.                Left-justify the result in the field.  Normally the
  2140.                result is right-justified.
  2141.          `+'
  2142.                For the signed `%d' and `%i' conversions and all inexact
  2143.                conversions, prefix a plus sign if the value is positive.
  2144.          ` '
  2145.                For the signed `%d' and `%i' conversions, if the result
  2146.                doesn't start with a plus or minus sign, prefix it with
  2147.                a space character instead.  Since the `+' flag ensures
  2148.                that the result includes a sign, this flag is ignored if
  2149.                both are specified.
  2150.          `#'
  2151.                For inexact conversions, `#' specifies that the result
  2152.                should always include a decimal point, even if no digits
  2153.                follow it.  For the `%g' and `%G' conversions, this also
  2154.                forces trailing zeros after the decimal point to be
  2155.                printed where they would otherwise be elided.
  2156.                For the `%o' conversion, force the leading digit to be
  2157.                `0', as if by increasing the precision.  For `%x' or
  2158.                `%X', prefix a leading `0x' or `0X' (respectively) to
  2159.                the result.  This doesn't do anything useful for the
  2160.                `%d', `%i', or `%u' conversions.  Using this flag
  2161.                produces output which can be parsed by the `scanf'
  2162.                functions with the `%i' conversion (*note Standard
  2163.                Formatted Input::.).
  2164.          `0'
  2165.                Pad the field with zeros instead of spaces.  The zeros
  2166.                are placed after any indication of sign or base.  This
  2167.                flag is ignored if the `-' flag is also specified, or if
  2168.                a precision is specified for an exact converson.
  2169.         * An optional decimal integer specifying the "minimum field
  2170.           width".  If the normal conversion produces fewer characters
  2171.           than this, the field is padded (with spaces or zeros per the
  2172.           `0' flag) to the specified width.  This is a *minimum* width;
  2173.           if the normal conversion produces more characters than this,
  2174.           the field is *not* truncated.
  2175.           Alternatively, if the field width is `*', the next argument
  2176.           in the argument list (before the actual value to be printed)
  2177.           is used as the field width.  The width value must be an
  2178.           integer.  If the value is negative it is as though the `-'
  2179.           flag is set (see above) and the absolute value is used as the
  2180.           field width.
  2181.         * An optional "precision" to specify the number of digits to be
  2182.           written for numeric conversions and the maximum field width
  2183.           for string conversions.  The precision is specified by a
  2184.           period (`.') followed optionally by a decimal integer (which
  2185.           defaults to zero if omitted).
  2186.           Alternatively, if the precision is `.*', the next argument in
  2187.           the argument list (before the actual value to be printed) is
  2188.           used as the precision.  The value must be an integer, and is
  2189.           ignored if negative.  If you specify `*' for both the field
  2190.           width and precision, the field width argument precedes the
  2191.           precision argument.  The `.*' precision is an enhancement.  C
  2192.           library versions may not accept this syntax.
  2193.           For the `%f', `%e', and `%E' conversions, the precision
  2194.           specifies how many digits follow the decimal-point character.
  2195.           The default precision is `6'.  If the precision is
  2196.           explicitly `0', the decimal point character is suppressed.
  2197.           For the `%g' and `%G' conversions, the precision specifies how
  2198.           many significant digits to print.  Significant digits are the
  2199.           first digit before the decimal point, and all the digits
  2200.           after it.  If the precision is `0' or not specified for `%g'
  2201.           or `%G', it is treated like a value of `1'.  If the value
  2202.           being printed cannot be expressed accurately in the specified
  2203.           number of digits, the value is rounded to the nearest number
  2204.           that fits.
  2205.           For exact conversions, if a precision is supplied it
  2206.           specifies the minimum number of digits to appear; leading
  2207.           zeros are produced if necessary.  If a precision is not
  2208.           supplied, the number is printed with as many digits as
  2209.           necessary.  Converting an exact `0' with an explicit
  2210.           precision of zero produces no characters.
  2211.         * An optional one of `l', `h' or `L', which is ignored for
  2212.           numeric conversions.  It is an error to specify these
  2213.           modifiers for non-numeric conversions.
  2214.         * A character that specifies the conversion to be applied.
  2215. Exact Conversions
  2216. .................
  2217.     `d', `i'
  2218.           Print an integer as a signed decimal number.  `%d' and `%i'
  2219.           are synonymous for output, but are different when used with
  2220.           `scanf' for input (*note Standard Formatted Input::.).
  2221.     `o'
  2222.           Print an integer as an unsigned octal number.
  2223.     `u'
  2224.           Print an integer as an unsigned decimal number.
  2225.     `x', `X'
  2226.           Print an integer as an unsigned hexadecimal number.  `%x'
  2227.           prints using the digits `0123456789abcdef'.  `%X' prints
  2228.           using the digits `0123456789ABCDEF'.
  2229. Inexact Conversions
  2230. ...................
  2231.     `f'
  2232.           Print a floating-point number in fixed-point notation.
  2233.     `e', `E'
  2234.           Print a floating-point number in exponential notation.  `%e'
  2235.           prints `e' between mantissa and exponont.  `%E' prints `E'
  2236.           between mantissa and exponont.
  2237.     `g', `G'
  2238.           Print a floating-point number in either normal or exponential
  2239.           notation, whichever is more appropriate for its magnitude.
  2240.           Unless an `#' flag has been supplied trailing zeros after a
  2241.           decimal point will be stripped off. `%g' prints `e' between
  2242.           mantissa and exponont.  `%G' prints `E' between mantissa and
  2243.           exponent.
  2244. Other Conversions
  2245. .................
  2246.     `c'
  2247.           Print a single character.  The `-' flag is the only one which
  2248.           can be specified.  It is an error to specify a precision.
  2249.     `s'
  2250.           Print a string.  The `-' flag is the only one which can be
  2251.           specified.  A precision specifies the maximum number of
  2252.           characters to output; otherwise all characters in the string
  2253.           are output.
  2254.     `a', `A'
  2255.           Print a scheme expression.  The `-' flag left-justifies the
  2256.           output.  The `#' flag specifies that strings and characters
  2257.           should be quoted as by `write' (which can be read using
  2258.           `read'); otherwise, output is as `display' prints.  A
  2259.           precision specifies the maximum number of characters to
  2260.           output; otherwise as many characters as needed are output.
  2261.           *Note:* `%a' and `%A' are SLIB extensions.
  2262.     `%'
  2263.           Print a literal `%' character.  No argument is consumed.  It
  2264.           is an error to specifiy flags, field width, precision, or
  2265.           type modifiers with `%%'.
  2266. File: slib.info,  Node: Standard Formatted Input,  Prev: Standard Formatted Output,  Up: Standard Formatted I/O
  2267. Standard Formatted Input
  2268. ------------------------
  2269.   `(require 'scanf)'
  2270.  - Function: scanf-read-list FORMAT
  2271.  - Function: scanf-read-list FORMAT PORT
  2272.  - Function: scanf-read-list FORMAT STRING
  2273.  - Macro: scanf FORMAT ARG1 ...
  2274.  - Macro: fscanf PORT FORMAT ARG1 ...
  2275.  - Macro: sscanf STR FORMAT ARG1 ...
  2276.      Each function reads characters, interpreting them according to the
  2277.      control string FORMAT argument.
  2278.      `scanf-read-list' returns a list of the items specified as far as
  2279.      the input matches FORMAT.  `scanf', `fscanf', and `sscanf' return
  2280.      the number of items successfully matched and stored.  `scanf',
  2281.      `fscanf', and `sscanf' also set the location corresponding to ARG1
  2282.      ... using the methods:
  2283.     symbol
  2284.           `set!'
  2285.     car expression
  2286.           `set-car!'
  2287.     cdr expression
  2288.           `set-cdr!'
  2289.     vector-ref expression
  2290.           `vector-set!'
  2291.     substring expression
  2292.           `substring-move-left!'
  2293.      The argument to a `substring' expression in ARG1 ... must be a
  2294.      non-constant string.  Characters will be stored starting at the
  2295.      position specified by the second argument to `substring'.  The
  2296.      number of characters stored will be limited by either the position
  2297.      specified by the third argument to `substring' or the length of the
  2298.      matched string, whichever is less.
  2299.      The control string, FORMAT, contains conversion specifications and
  2300.      other characters used to direct interpretation of input sequences.
  2301.      The control string contains:
  2302.         * White-space characters (blanks, tabs, newlines, or formfeeds)
  2303.           that cause input to be read (and discarded) up to the next
  2304.           non-white-space character.
  2305.         * An ordinary character (not `%') that must match the next
  2306.           character of the input stream.
  2307.         * Conversion specifications, consisting of the character `%', an
  2308.           optional assignment suppressing character `*', an optional
  2309.           numerical maximum-field width, an optional `l', `h' or `L'
  2310.           which is ignored, and a conversion code.
  2311.      Unless the specification contains the `n' conversion character
  2312.      (described below), a conversion specification directs the
  2313.      conversion of the next input field.  The result of a conversion
  2314.      specification is returned in the position of the corresponding
  2315.      argument points, unless `*' indicates assignment suppression.
  2316.      Assignment suppression provides a way to describe an input field
  2317.      to be skipped.  An input field is defined as a string of
  2318.      characters; it extends to the next inappropriate character or
  2319.      until the field width, if specified, is exhausted.
  2320.           *Note:* This specification of format strings differs from the
  2321.           `ANSI C' and `POSIX' specifications.  In SLIB, white space
  2322.           before an input field is not skipped unless white space
  2323.           appears before the conversion specification in the format
  2324.           string.  In order to write format strings which work
  2325.           identically with `ANSI C' and SLIB, prepend whitespace to all
  2326.           conversion specifications except `[' and `c'.
  2327.      The conversion code indicates the interpretation of the input
  2328.      field; For a suppressed field, no value is returned.  The
  2329.      following conversion codes are legal:
  2330.     `%'
  2331.           A single % is expected in the input at this point; no value
  2332.           is returned.
  2333.     `d', `D'
  2334.           A decimal integer is expected.
  2335.     `u', `U'
  2336.           An unsigned decimal integer is expected.
  2337.     `o', `O'
  2338.           An octal integer is expected.
  2339.     `x', `X'
  2340.           A hexadecimal integer is expected.
  2341.     `i'
  2342.           An integer is expected.  Returns the value of the next input
  2343.           item, interpreted according to C conventions; a leading `0'
  2344.           implies octal, a leading `0x' implies hexadecimal; otherwise,
  2345.           decimal is assumed.
  2346.     `n'
  2347.           Returns the total number of bytes (including white space)
  2348.           read by `scanf'.  No input is consumed by `%n'.
  2349.     `f', `F', `e', `E', `g', `G'
  2350.           A floating-point number is expected.  The input format for
  2351.           floating-point numbers is an optionally signed string of
  2352.           digits, possibly containing a radix character `.', followed
  2353.           by an optional exponent field consisting of an `E' or an `e',
  2354.           followed by an optional `+', `-', or space, followed by an
  2355.           integer.
  2356.     `c', `C'
  2357.           WIDTH characters are expected.  The normal
  2358.           skip-over-white-space is suppressed in this case; to read the
  2359.           next non-space character, use `%1s'.  If a field width is
  2360.           given, a string is returned; up to the indicated number of
  2361.           characters is read.
  2362.     `s', `S'
  2363.           A character string is expected The input field is terminated
  2364.           by a white-space character.  `scanf' cannot read a null
  2365.           string.
  2366.     `['
  2367.           Indicates string data and the normal
  2368.           skip-over-leading-white-space is suppressed.  The left
  2369.           bracket is followed by a set of characters, called the
  2370.           scanset, and a right bracket; the input field is the maximal
  2371.           sequence of input characters consisting entirely of
  2372.           characters in the scanset.  `^', when it appears as the first
  2373.           character in the scanset, serves as a complement operator and
  2374.           redefines the scanset as the set of all characters not
  2375.           contained in the remainder of the scanset string.
  2376.           Construction of the scanset follows certain conventions.  A
  2377.           range of characters may be represented by the construct
  2378.           first-last, enabling `[0123456789]' to be expressed `[0-9]'.
  2379.           Using this convention, first must be lexically less than or
  2380.           equal to last; otherwise, the dash stands for itself.  The
  2381.           dash also stands for itself when it is the first or the last
  2382.           character in the scanset.  To include the right square
  2383.           bracket as an element of the scanset, it must appear as the
  2384.           first character (possibly preceded by a `^') of the scanset,
  2385.           in which case it will not be interpreted syntactically as the
  2386.           closing bracket.  At least one character must match for this
  2387.           conversion to succeed.
  2388.      The `scanf' functions terminate their conversions at end-of-file,
  2389.      at the end of the control string, or when an input character
  2390.      conflicts with the control string.  In the latter case, the
  2391.      offending character is left unread in the input stream.
  2392. File: slib.info,  Node: Programs and Arguments,  Next: HTML HTTP and CGI,  Prev: Standard Formatted I/O,  Up: Textual Conversion Packages
  2393. Program and Arguments
  2394. =====================
  2395. * Menu:
  2396. * Getopt::                      Command Line option parsing
  2397. * Command Line::                A command line reader for Scheme shells
  2398. * Parameter lists::             'parameters
  2399. * Getopt Parameter lists::      'getopt-parameters
  2400. * Filenames::                   'glob or 'filename
  2401. * Batch::                       'batch
  2402. File: slib.info,  Node: Getopt,  Next: Command Line,  Prev: Programs and Arguments,  Up: Programs and Arguments
  2403. Getopt
  2404. ------
  2405.   `(require 'getopt)'
  2406.   This routine implements Posix command line argument parsing.  Notice
  2407. that returning values through global variables means that `getopt' is
  2408. *not* reentrant.
  2409.  - Variable: *optind*
  2410.      Is the index of the current element of the command line.  It is
  2411.      initially one.  In order to parse a new command line or reparse an
  2412.      old one, *OPTING* must be reset.
  2413.  - Variable: *optarg*
  2414.      Is set by getopt to the (string) option-argument of the current
  2415.      option.
  2416.  - Procedure: getopt ARGC ARGV OPTSTRING
  2417.      Returns the next option letter in ARGV (starting from `(vector-ref
  2418.      argv *optind*)') that matches a letter in OPTSTRING.  ARGV is a
  2419.      vector or list of strings, the 0th of which getopt usually
  2420.      ignores. ARGC is the argument count, usually the length of ARGV.
  2421.      OPTSTRING is a string of recognized option characters; if a
  2422.      character is followed by a colon, the option takes an argument
  2423.      which may be immediately following it in the string or in the next
  2424.      element of ARGV.
  2425.      *OPTIND* is the index of the next element of the ARGV vector to be
  2426.      processed.  It is initialized to 1 by `getopt.scm', and `getopt'
  2427.      updates it when it finishes with each element of ARGV.
  2428.      `getopt' returns the next option character from ARGV that matches
  2429.      a character in OPTSTRING, if there is one that matches.  If the
  2430.      option takes an argument, `getopt' sets the variable *OPTARG* to
  2431.      the option-argument as follows:
  2432.         * If the option was the last character in the string pointed to
  2433.           by an element of ARGV, then *OPTARG* contains the next
  2434.           element of ARGV, and *OPTIND* is incremented by 2.  If the
  2435.           resulting value of *OPTIND* is greater than or equal to ARGC,
  2436.           this indicates a missing option argument, and `getopt'
  2437.           returns an error indication.
  2438.         * Otherwise, *OPTARG* is set to the string following the option
  2439.           character in that element of ARGV, and *OPTIND* is
  2440.           incremented by 1.
  2441.      If, when `getopt' is called, the string `(vector-ref argv
  2442.      *optind*)' either does not begin with the character `#\-' or is
  2443.      just `"-"', `getopt' returns `#f' without changing *OPTIND*.  If
  2444.      `(vector-ref argv *optind*)' is the string `"--"', `getopt'
  2445.      returns `#f' after incrementing *OPTIND*.
  2446.      If `getopt' encounters an option character that is not contained in
  2447.      OPTSTRING, it returns the question-mark `#\?' character.  If it
  2448.      detects a missing option argument, it returns the colon character
  2449.      `#\:' if the first character of OPTSTRING was a colon, or a
  2450.      question-mark character otherwise.  In either case, `getopt' sets
  2451.      the variable GETOPT:OPT to the option character that caused the
  2452.      error.
  2453.      The special option `"--"' can be used to delimit the end of the
  2454.      options; `#f' is returned, and `"--"' is skipped.
  2455.      RETURN VALUE
  2456.      `getopt' returns the next option character specified on the command
  2457.      line.  A colon `#\:' is returned if `getopt' detects a missing
  2458.      argument and the first character of OPTSTRING was a colon `#\:'.
  2459.      A question-mark `#\?' is returned if `getopt' encounters an option
  2460.      character not in OPTSTRING or detects a missing argument and the
  2461.      first character of OPTSTRING was not a colon `#\:'.
  2462.      Otherwise, `getopt' returns `#f' when all command line options
  2463.      have been parsed.
  2464.      Example:
  2465.           #! /usr/local/bin/scm
  2466.           ;;;This code is SCM specific.
  2467.           (define argv (program-arguments))
  2468.           (require 'getopt)
  2469.           
  2470.           (define opts ":a:b:cd")
  2471.           (let loop ((opt (getopt (length argv) argv opts)))
  2472.             (case opt
  2473.               ((#\a) (print "option a: " *optarg*))
  2474.               ((#\b) (print "option b: " *optarg*))
  2475.               ((#\c) (print "option c"))
  2476.               ((#\d) (print "option d"))
  2477.               ((#\?) (print "error" getopt:opt))
  2478.               ((#\:) (print "missing arg" getopt:opt))
  2479.               ((#f) (if (< *optind* (length argv))
  2480.                         (print "argv[" *optind* "]="
  2481.                                (list-ref argv *optind*)))
  2482.                     (set! *optind* (+ *optind* 1))))
  2483.             (if (< *optind* (length argv))
  2484.                 (loop (getopt (length argv) argv opts))))
  2485.           
  2486.           (slib:exit)
  2487. Getopt-
  2488. -------
  2489.  - Function: getopt- ARGC ARGV OPTSTRING
  2490.      The procedure `getopt--' is an extended version of `getopt' which
  2491.      parses "long option names" of the form `--hold-the-onions' and
  2492.      `--verbosity-level=extreme'.  `Getopt--' behaves as `getopt'
  2493.      except for non-empty options beginning with `--'.
  2494.      Options beginning with `--' are returned as strings rather than
  2495.      characters.  If a value is assigned (using `=') to a long option,
  2496.      `*optarg*' is set to the value.  The `=' and value are not
  2497.      returned as part of the option string.
  2498.      No information is passed to `getopt--' concerning which long
  2499.      options should be accepted or whether such options can take
  2500.      arguments.  If a long option did not have an argument, `*optarg'
  2501.      will be set to `#f'.  The caller is responsible for detecting and
  2502.      reporting errors.
  2503.           (define opts ":-:b:")
  2504.           (define argc 5)
  2505.           (define argv '("foo" "-b9" "--f1" "--2=" "--g3=35234.342" "--"))
  2506.           (define *optind* 1)
  2507.           (define *optarg* #f)
  2508.           (require 'qp)
  2509.           (do ((i 5 (+ -1 i)))
  2510.               ((zero? i))
  2511.             (define opt (getopt-- argc argv opts))
  2512.             (print *optind* opt *optarg*)))
  2513.           -|
  2514.           2 #\b "9"
  2515.           3 "f1" #f
  2516.           4 "2" ""
  2517.           5 "g3" "35234.342"
  2518.           5 #f "35234.342"
  2519. File: slib.info,  Node: Command Line,  Next: Parameter lists,  Prev: Getopt,  Up: Programs and Arguments
  2520. Command Line
  2521. ------------
  2522.   `(require 'read-command)'
  2523.  - Function: read-command PORT
  2524.  - Function: read-command
  2525.      `read-command' converts a "command line" into a list of strings
  2526.      suitable for parsing by `getopt'.  The syntax of command lines
  2527.      supported resembles that of popular "shell"s.  `read-command'
  2528.      updates PORT to point to the first character past the command
  2529.      delimiter.
  2530.      If an end of file is encountered in the input before any
  2531.      characters are found that can begin an object or comment, then an
  2532.      end of file object is returned.
  2533.      The PORT argument may be omitted, in which case it defaults to the
  2534.      value returned by `current-input-port'.
  2535.      The fields into which the command line is split are delimited by
  2536.      whitespace as defined by `char-whitespace?'.  The end of a command
  2537.      is delimited by end-of-file or unescaped semicolon (<;>) or
  2538.      <newline>.  Any character can be literally included in a field by
  2539.      escaping it with a backslach (<\>).
  2540.      The initial character and types of fields recognized are:
  2541.     `\'
  2542.           The next character has is taken literally and not interpreted
  2543.           as a field delimiter.  If <\> is the last character before a
  2544.           <newline>, that <newline> is just ignored.  Processing
  2545.           continues from the characters after the <newline> as though
  2546.           the backslash and <newline> were not there.
  2547.     `"'
  2548.           The characters up to the next unescaped <"> are taken
  2549.           literally, according to [R4RS] rules for literal strings
  2550.           (*note Strings: (r4rs)Strings.).
  2551.     `(', `%''
  2552.           One scheme expression is `read' starting with this character.
  2553.           The `read' expression is evaluated, converted to a string
  2554.           (using `display'), and replaces the expression in the returned
  2555.           field.
  2556.     `;'
  2557.           Semicolon delimits a command.  Using semicolons more than one
  2558.           command can appear on a line.  Escaped semicolons and
  2559.           semicolons inside strings do not delimit commands.
  2560.      The comment field differs from the previous fields in that it must
  2561.      be the first character of a command or appear after whitespace in
  2562.      order to be recognized.  <#> can be part of fields if these
  2563.      conditions are not met.  For instance, `ab#c' is just the field
  2564.      ab#c.
  2565.     `#'
  2566.           Introduces a comment.  The comment continues to the end of
  2567.           the line on which the semicolon appears.  Comments are
  2568.           treated as whitespace by `read-dommand-line' and backslashes
  2569.           before <newline>s in comments are also ignored.
  2570.  - Function: read-options-file FILENAME
  2571.      `read-options-file' converts an "options file" into a list of
  2572.      strings suitable for parsing by `getopt'.  The syntax of options
  2573.      files is the same as the syntax for command lines, except that
  2574.      <newline>s do not terminate reading (only <;> or end of file).
  2575.      If an end of file is encountered before any characters are found
  2576.      that can begin an object or comment, then an end of file object is
  2577.      returned.
  2578. File: slib.info,  Node: Parameter lists,  Next: Getopt Parameter lists,  Prev: Command Line,  Up: Programs and Arguments
  2579. Parameter lists
  2580. ---------------
  2581.   `(require 'parameters)'
  2582. Arguments to procedures in scheme are distinguished from each other by
  2583. their position in the procedure call.  This can be confusing when a
  2584. procedure takes many arguments, many of which are not often used.
  2585. A "parameter-list" is a way of passing named information to a
  2586. procedure.  Procedures are also defined to set unused parameters to
  2587. default values, check parameters, and combine parameter lists.
  2588. A PARAMETER has the form `(parameter-name value1 ...)'.  This format
  2589. allows for more than one value per parameter-name.
  2590. A PARAMETER-LIST is a list of PARAMETERs, each with a different
  2591. PARAMETER-NAME.
  2592.  - Function: make-parameter-list PARAMETER-NAMES
  2593.      Returns an empty parameter-list with slots for PARAMETER-NAMES.
  2594.  - Function: parameter-list-ref PARAMETER-LIST PARAMETER-NAME
  2595.      PARAMETER-NAME must name a valid slot of PARAMETER-LIST.
  2596.      `parameter-list-ref' returns the value of parameter PARAMETER-NAME
  2597.      of PARAMETER-LIST.
  2598.  - Procedure: adjoin-parameters! PARAMETER-LIST PARAMETER1 ...
  2599.      Returns PARAMETER-LIST with PARAMETER1 ... merged in.
  2600.  - Procedure: parameter-list-expand EXPANDERS PARAMETER-LIST
  2601.      EXPANDERS is a list of procedures whose order matches the order of
  2602.      the PARAMETER-NAMEs in the call to `make-parameter-list' which
  2603.      created PARAMETER-LIST.  For each non-false element of EXPANDERS
  2604.      that procedure is mapped over the corresponding parameter value
  2605.      and the returned parameter lists are merged into PARAMETER-LIST.
  2606.      This process is repeated until PARAMETER-LIST stops growing.  The
  2607.      value returned from `parameter-list-expand' is unspecified.
  2608.  - Function: fill-empty-parameters DEFAULTERS PARAMETER-LIST
  2609.      DEFAULTERS is a list of procedures whose order matches the order
  2610.      of the PARAMETER-NAMEs in the call to `make-parameter-list' which
  2611.      created PARAMETER-LIST.  `fill-empty-parameters' returns a new
  2612.      parameter-list with each empty parameter replaced with the list
  2613.      returned by calling the corresponding DEFAULTER with
  2614.      PARAMETER-LIST as its argument.
  2615.  - Function: check-parameters CHECKS PARAMETER-LIST
  2616.      CHECKS is a list of procedures whose order matches the order of
  2617.      the PARAMETER-NAMEs in the call to `make-parameter-list' which
  2618.      created PARAMETER-LIST.
  2619.      `check-parameters' returns PARAMETER-LIST if each CHECK of the
  2620.      corresponding PARAMETER-LIST returns non-false.  If some CHECK
  2621.      returns `#f' an error is signaled.
  2622. In the following procedures ARITIES is a list of symbols.  The elements
  2623. of `arities' can be:
  2624. `single'
  2625.      Requires a single parameter.
  2626. `optional'
  2627.      A single parameter or no parameter is acceptable.
  2628. `boolean'
  2629.      A single boolean parameter or zero parameters is acceptable.
  2630. `nary'
  2631.      Any number of parameters are acceptable.
  2632. `nary1'
  2633.      One or more of parameters are acceptable.
  2634.  - Function: parameter-list->arglist POSITIONS ARITIES TYPES
  2635.           PARAMETER-LIST
  2636.      Returns PARAMETER-LIST converted to an argument list.  Parameters
  2637.      of ARITY type `single' and `boolean' are converted to the single
  2638.      value associated with them.  The other ARITY types are converted
  2639.      to lists of the value(s) of type TYPES.
  2640.      POSITIONS is a list of positive integers whose order matches the
  2641.      order of the PARAMETER-NAMEs in the call to `make-parameter-list'
  2642.      which created PARAMETER-LIST.  The integers specify in which
  2643.      argument position the corresponding parameter should appear.
  2644. File: slib.info,  Node: Getopt Parameter lists,  Next: Filenames,  Prev: Parameter lists,  Up: Programs and Arguments
  2645. Getopt Parameter lists
  2646. ----------------------
  2647.   `(require 'getopt-parameters)'
  2648.  - Function: getopt->parameter-list ARGC ARGV OPTNAMES ARITIES TYPES
  2649.           ALIASES
  2650.      Returns ARGV converted to a parameter-list.  OPTNAMES are the
  2651.      parameter-names.  ALIASES is a list of lists of strings and
  2652.      elements of OPTNAMES.  Each of these strings which have length of
  2653.      1 will be treated as a single <-> option by `getopt'.  Longer
  2654.      strings will be treated as long-named options (*note getopt-:
  2655.      Getopt.).
  2656.  - Function: getopt->arglist ARGC ARGV OPTNAMES POSITIONS ARITIES TYPES
  2657.           DEFAULTERS CHECKS ALIASES
  2658.      Like `getopt->parameter-list', but converts ARGV to an
  2659.      argument-list as specified by OPTNAMES, POSITIONS, ARITIES, TYPES,
  2660.      DEFAULTERS, CHECKS, and ALIASES.
  2661. These `getopt' functions can be used with SLIB relational databases.
  2662. For an example, *Note make-command-server: Database Utilities.
  2663. If errors are encountered while processing options, directions for using
  2664. the options are printed to `current-error-port'.
  2665.      (begin
  2666.        (set! *optind* 1)
  2667.        (getopt->parameter-list
  2668.         2
  2669.         '("cmd" "-?")
  2670.         '(flag number symbols symbols string flag2 flag3 num2 num3)
  2671.         '(boolean optional nary1 nary single boolean boolean nary nary)
  2672.         '(boolean integer symbol symbol string boolean boolean integer integer)
  2673.         '(("flag" flag)
  2674.           ("f" flag)
  2675.           ("Flag" flag2)
  2676.           ("B" flag3)
  2677.           ("optional" number)
  2678.           ("o" number)
  2679.           ("nary1" symbols)
  2680.           ("N" symbols)
  2681.           ("nary" symbols)
  2682.           ("n" symbols)
  2683.           ("single" string)
  2684.           ("s" string)
  2685.           ("a" num2)
  2686.           ("Abs" num3))))
  2687.      -|
  2688.      Usage: cmd [OPTION ARGUMENT ...] ...
  2689.      
  2690.        -f, --flag
  2691.        -o, --optional=<number>
  2692.        -n, --nary=<symbols> ...
  2693.        -N, --nary1=<symbols> ...
  2694.        -s, --single=<string>
  2695.            --Flag
  2696.        -B
  2697.        -a        <num2> ...
  2698.            --Abs=<num3> ...
  2699.      
  2700.      ERROR: getopt->parameter-list "unrecognized option" "-?"
  2701. File: slib.info,  Node: Filenames,  Next: Batch,  Prev: Getopt Parameter lists,  Up: Programs and Arguments
  2702. Filenames
  2703. ---------
  2704.   `(require 'filename)' or `(require 'glob)'
  2705.  - Function: filename:match?? PATTERN
  2706.  - Function: filename:match-ci?? PATTERN
  2707.      Returns a predicate which returns a non-false value if its string        |
  2708.      argument matches (the string) PATTERN, false otherwise.  Filename        |
  2709.      matching is like "glob" expansion described the bash manpage,            |
  2710.      except that names beginning with `.' are matched and `/'                 |
  2711.      characters are not treated specially.                                    |
  2712.      These functions interpret the following characters specially in
  2713.      PATTERN strings:
  2714.     `*'
  2715.           Matches any string, including the null string.
  2716.     `?'
  2717.           Matches any single character.
  2718.     `[...]'
  2719.           Matches any one of the enclosed characters.  A pair of
  2720.           characters separated by a minus sign (-) denotes a range; any
  2721.           character lexically between those two characters, inclusive,
  2722.           is matched.  If the first character following the `[' is a
  2723.           `!' or a `^' then any character not enclosed is matched.  A
  2724.           `-' or `]' may be matched by including it as the first or
  2725.           last character in the set.
  2726.  - Function: filename:substitute?? PATTERN TEMPLATE                           |
  2727.  - Function: filename:substitute-ci?? PATTERN TEMPLATE                        |
  2728.      Returns a function transforming a single string argument according       |
  2729.      to glob patterns PATTERN and TEMPLATE.  PATTERN and TEMPLATE must        |
  2730.      have the same number of wildcard specifications, which need not be       |
  2731.      identical.  PATTERN and TEMPLATE may have a different number of          |
  2732.      literal sections. If an argument to the function matches PATTERN         |
  2733.      in the sense of `filename:match??' then it returns a copy of             |
  2734.      TEMPLATE in which each wildcard specification is replaced by the         |
  2735.      part of the argument matched by the corresponding wildcard               |
  2736.      specification in PATTERN.  A `*' wildcard matches the longest            |
  2737.      leftmost string possible.  If the argument does not match PATTERN        |
  2738.      then false is returned.                                                  |
  2739.                                                                               |
  2740.           ((filename:substitute?? "scm_[0-9]*.html" "scm5c4_??.htm")          |
  2741.            "scm_10.html")                                                     |
  2742.           => "scm5c4_10.htm"                                                  |
  2743.           ((filename:substitute?? "??" "beg?mid?end") "AZ")                   |
  2744.           => "begAmidZend"                                                    |
  2745.           ((filename:substitute?? "*na*" "?NA?") "banana")                    |
  2746.           => "banaNA"                                                         |
  2747.  - Function: replace-suffix STR OLD NEW
  2748.      STR can be a string or a list of strings.  Returns a new string
  2749.      (or strings) similar to `str' but with the suffix string OLD
  2750.      removed and the suffix string NEW appended.  If the end of STR
  2751.      does not match OLD, an error is signaled.
  2752.           (replace-suffix "/usr/local/lib/slib/batch.scm" ".scm" ".c")
  2753.           => "/usr/local/lib/slib/batch.c"
  2754. File: slib.info,  Node: Batch,  Prev: Filenames,  Up: Programs and Arguments
  2755. Batch
  2756. -----
  2757.   `(require 'batch)'
  2758. The batch procedures provide a way to write and execute portable scripts
  2759. for a variety of operating systems.  Each `batch:' procedure takes as
  2760. its first argument a parameter-list (*note Parameter lists::.).  This
  2761. parameter-list argument PARMS contains named associations.  Batch
  2762. currently uses 2 of these:
  2763. `batch-port'
  2764.      The port on which to write lines of the batch file.
  2765. `batch-dialect'
  2766.      The syntax of batch file to generate.  Currently supported are:
  2767.         * unix
  2768.         * dos
  2769.         * vms
  2770.         * amigados                                                            |
  2771.                                                                               |
  2772.         * system
  2773.         * *unknown*
  2774. `batch.scm' uses 2 enhanced relational tables (*note Database
  2775. Utilities::.) to store information linking the names of
  2776. `operating-system's to `batch-dialect'es.
  2777.  - Function: batch:initialize! DATABASE
  2778.      Defines `operating-system' and `batch-dialect' tables and adds the
  2779.      domain `operating-system' to the enhanced relational database
  2780.      DATABASE.
  2781.  - Variable: batch:platform
  2782.      Is batch's best guess as to which operating-system it is running
  2783.      under.  `batch:platform' is set to `(software-type)' (*note
  2784.      Configuration::.) unless `(software-type)' is `unix', in which
  2785.      case finer distinctions are made.
  2786.  - Function: batch:call-with-output-script PARMS FILE PROC
  2787.      PROC should be a procedure of one argument.  If FILE is an
  2788.      output-port, `batch:call-with-output-script' writes an appropriate
  2789.      header to FILE and then calls PROC with FILE as the only argument.
  2790.      If FILE is a string, `batch:call-with-output-script' opens a
  2791.      output-file of name FILE, writes an appropriate header to FILE,
  2792.      and then calls PROC with the newly opened port as the only
  2793.      argument.  Otherwise, `batch:call-with-output-script' acts as if
  2794.      it was called with the result of `(current-output-port)' as its
  2795.      third argument.
  2796.  - Function: batch:apply-chop-to-fit PROC ARG1 ARG2 ... LIST
  2797.      The procedure PROC must accept at least one argument and return
  2798.      `#t' if successful, `#f' if not.  `batch:apply-chop-to-fit' calls
  2799.      PROC with ARG1, ARG2, ..., and CHUNK, where CHUNK is a subset of
  2800.      LIST.  `batch:apply-chop-to-fit' tries PROC with successively
  2801.      smaller subsets of LIST until either PROC returns non-false, or
  2802.      the CHUNKs become empty.
  2803. The rest of the `batch:' procedures write (or execute if
  2804. `batch-dialect' is `system') commands to the batch port which has been
  2805. added to PARMS or `(copy-tree PARMS)' by the code:
  2806.      (adjoin-parameters! PARMS (list 'batch-port PORT))
  2807.  - Function: batch:system PARMS STRING1 STRING2 ...
  2808.      Calls `batch:try-system' (below) with arguments, but signals an
  2809.      error if `batch:try-system' returns `#f'.
  2810. These functions return a non-false value if the command was successfully
  2811. translated into the batch dialect and `#f' if not.  In the case of the
  2812. `system' dialect, the value is non-false if the operation suceeded.
  2813.  - Function: batch:try-system PARMS STRING1 STRING2 ...
  2814.      Writes a command to the `batch-port' in PARMS which executes the
  2815.      program named STRING1 with arguments STRING2 ....
  2816.  - Function: batch:run-script PARMS STRING1 STRING2 ...
  2817.      Writes a command to the `batch-port' in PARMS which executes the
  2818.      batch script named STRING1 with arguments STRING2 ....
  2819.      *Note:* `batch:run-script' and `batch:try-system' are not the same
  2820.      for some operating systems (VMS).
  2821.  - Function: batch:comment PARMS LINE1 ...
  2822.      Writes comment lines LINE1 ... to the `batch-port' in PARMS.
  2823.  - Function: batch:lines->file PARMS FILE LINE1 ...
  2824.      Writes commands to the `batch-port' in PARMS which create a file
  2825.      named FILE with contents LINE1 ....
  2826.  - Function: batch:delete-file PARMS FILE
  2827.      Writes a command to the `batch-port' in PARMS which deletes the
  2828.      file named FILE.
  2829.  - Function: batch:rename-file PARMS OLD-NAME NEW-NAME
  2830.      Writes a command to the `batch-port' in PARMS which renames the
  2831.      file OLD-NAME to NEW-NAME.
  2832. In addition, batch provides some small utilities very useful for writing
  2833. scripts:
  2834.  - Function: truncate-up-to PATH CHAR
  2835.  - Function: truncate-up-to PATH STRING
  2836.  - Function: truncate-up-to PATH CHARLIST
  2837.      PATH can be a string or a list of strings.  Returns PATH sans any
  2838.      prefixes ending with a character of the second argument.  This can
  2839.      be used to derive a filename moved locally from elsewhere.
  2840.           (truncate-up-to "/usr/local/lib/slib/batch.scm" "/")
  2841.           => "batch.scm"
  2842.  - Function: string-join JOINER STRING1 ...
  2843.      Returns a new string consisting of all the strings STRING1 ...  in
  2844.      order appended together with the string JOINER between each
  2845.      adjacent pair.
  2846.  - Function: must-be-first LIST1 LIST2
  2847.      Returns a new list consisting of the elements of LIST2 ordered so
  2848.      that if some elements of LIST1 are `equal?' to elements of LIST2,
  2849.      then those elements will appear first and in the order of LIST1.
  2850.  - Function: must-be-last LIST1 LIST2
  2851.      Returns a new list consisting of the elements of LIST1 ordered so
  2852.      that if some elements of LIST2 are `equal?' to elements of LIST1,
  2853.      then those elements will appear last and in the order of LIST2.
  2854.  - Function: os->batch-dialect OSNAME
  2855.      Returns its best guess for the `batch-dialect' to be used for the
  2856.      operating-system named OSNAME.  `os->batch-dialect' uses the
  2857.      tables added to DATABASE by `batch:initialize!'.
  2858. Here is an example of the use of most of batch's procedures:
  2859.      (require 'database-utilities)
  2860.      (require 'parameters)
  2861.      (require 'batch)
  2862.      (require 'glob)
  2863.      
  2864.      (define batch (create-database #f 'alist-table))
  2865.      (batch:initialize! batch)
  2866.      
  2867.      (define my-parameters
  2868.        (list (list 'batch-dialect (os->batch-dialect batch:platform))
  2869.              (list 'platform batch:platform)
  2870.              (list 'batch-port (current-output-port)))) ;gets filled in later
  2871.      
  2872.      (batch:call-with-output-script
  2873.       my-parameters
  2874.       "my-batch"
  2875.       (lambda (batch-port)
  2876.         (adjoin-parameters! my-parameters (list 'batch-port batch-port))
  2877.         (and
  2878.          (batch:comment my-parameters
  2879.                         "================ Write file with C program.")
  2880.          (batch:rename-file my-parameters "hello.c" "hello.c~")
  2881.          (batch:lines->file my-parameters "hello.c"
  2882.                             "#include <stdio.h>"
  2883.                             "int main(int argc, char **argv)"
  2884.                             "{"
  2885.                             "  printf(\"hello world\\n\");"
  2886.                             "  return 0;"
  2887.                             "}" )
  2888.          (batch:system my-parameters "cc" "-c" "hello.c")
  2889.          (batch:system my-parameters "cc" "-o" "hello"
  2890.                        (replace-suffix "hello.c" ".c" ".o"))
  2891.          (batch:system my-parameters "hello")
  2892.          (batch:delete-file my-parameters "hello")
  2893.          (batch:delete-file my-parameters "hello.c")
  2894.          (batch:delete-file my-parameters "hello.o")
  2895.          (batch:delete-file my-parameters "my-batch")
  2896.          )))
  2897. Produces the file `my-batch':
  2898.      #!/bin/sh
  2899.      # "my-batch" build script created Sat Jun 10 21:20:37 1995
  2900.      # ================ Write file with C program.
  2901.      mv -f hello.c hello.c~
  2902.      rm -f hello.c
  2903.      echo '#include <stdio.h>'>>hello.c
  2904.      echo 'int main(int argc, char **argv)'>>hello.c
  2905.      echo '{'>>hello.c
  2906.      echo '  printf("hello world\n");'>>hello.c
  2907.      echo '  return 0;'>>hello.c
  2908.      echo '}'>>hello.c
  2909.      cc -c hello.c
  2910.      cc -o hello hello.o
  2911.      hello
  2912.      rm -f hello
  2913.      rm -f hello.c
  2914.      rm -f hello.o
  2915.      rm -f my-batch
  2916. When run, `my-batch' prints:
  2917.      bash$ my-batch
  2918.      mv: hello.c: No such file or directory
  2919.      hello world
  2920. File: slib.info,  Node: HTML HTTP and CGI,  Next: Printing Scheme,  Prev: Programs and Arguments,  Up: Textual Conversion Packages
  2921. HTML Forms
  2922. ==========
  2923.   `(require 'html-form)'
  2924.  - Variable: *html:output-port*
  2925.      Procedure names starting with `html:' send their output to the
  2926.      port *HTML:OUTPUT-PORT*.  *HTML:OUTPUT-PORT* is initially the
  2927.      current output port.
  2928.  - Function: make-atval TXT                                                   |
  2929.      Returns a string with character substitutions appropriate to send
  2930.      TXT as an "attribute-value".
  2931.  - Function: make-plain TXT                                                   |
  2932.      Returns a string with character substitutions appropriate to send
  2933.      TXT as an "plain-text".
  2934.  - Function: html:start-page TITLE BACKLINK TAGS ...                          |
  2935.  - Function: html:start-page TITLE BACKLINK                                   |
  2936.  - Function: html:start-page TITLE                                            |
  2937.      Outputs headers for an HTML page named TITLE.  If string arguments       |
  2938.      BACKLINK ... are supplied they are printed verbatim within the           |
  2939.      <HEAD> section.                                                          |
  2940.                                                                               |
  2941.  - Function: html:end-page                                                    |
  2942.      Outputs HTML codes to end a page.                                        |
  2943.                                                                               |
  2944.  - Function: html:pre LINE1 LINE ...                                          |
  2945.      Writes (using `html:printf') the strings LINE1, LINES as                 |
  2946.      "PRE"formmated plain text (rendered in fixed-width font).                |
  2947.      Newlines are inserted between LINE1, LINES.  HTML tags (`<tag>')         |
  2948.      within LINES will be visible verbatim.                                   |
  2949.                                                                               |
  2950.  - Function: html:comment LINE1 LINE ...                                      |
  2951.      Writes (using `html:printf') the strings LINE1 as HTML comments.         |
  2952.                                                                               |
  2953. HTML Tables                                                                   |
  2954. ===========                                                                   |
  2955.                                                                               |
  2956.  - Function: html:start-table CAPTION                                         |
  2957.                                                                               |
  2958.  - Function: html:end-table                                                   |
  2959.                                                                               |
  2960.  - Function: html:heading COLUMNS                                             |
  2961.      Outputs a heading row for the currently-started table.                   |
  2962.                                                                               |
  2963.  - Function: html:href-heading COLUMNS URLS                                   |
  2964.      Outputs a heading row with column-names COLUMNS linked to URLs           |
  2965.      URLS.                                                                    |
  2966.                                                                               |
  2967.  - Function: make-row-converter K FOREIGNS                                    |
  2968.      The positive integer K is the primary-key-limit (number of               |
  2969.      primary-keys) of the table.  FOREIGNS is a list of the filenames of      |
  2970.      foreign-key field pages and #f for non foreign-key fields.               |
  2971.                                                                               |
  2972.      `make-row-converter' returns a procedure taking a row for its            |
  2973.      single argument.  This returned procedure prints the table row to        |
  2974.      *HTML:OUTPUT-PORT*.                                                      |
  2975.                                                                               |
  2976.  - Function: table-name->filename TABLE-NAME                                  |
  2977.      Returns the symbol TABLE-NAME converted to a filename.                   |
  2978.                                                                               |
  2979.  - Function: table->html CAPTION DB TABLE-NAME MATCH-KEY1 ...                 |
  2980.      Writes HTML for DB table TABLE-NAME to *HTML:OUTPUT-PORT*.               |
  2981.                                                                               |
  2982.      The optional MATCH-KEY1 ... arguments restrict actions to a subset       |
  2983.      of the table.  *Note match-key: Table Operations.                        |
  2984.                                                                               |
  2985.  - Function: table->page DB TABLE-NAME INDEX-FILENAME                         |
  2986.      Writes a complete HTML page to *HTML:OUTPUT-PORT*.  The string           |
  2987.      INDEX-FILENAME names the page which refers to this one.                  |
  2988.                                                                               |
  2989.  - Function: catalog->html DB CAPTION                                         |
  2990.      Writes HTML for the catalog table of DB to *HTML:OUTPUT-PORT*.           |
  2991.                                                                               |
  2992.  - Function: catalog->page DB CAPTION                                         |
  2993.      Writes a complete HTML page for the catalog of DB to                     |
  2994.      *HTML:OUTPUT-PORT*.                                                      |
  2995.                                                                               |
  2996. HTML Forms                                                                    |
  2997. ==========                                                                    |
  2998.  - Function: html:start-form METHOD ACTION
  2999.      The symbol METHOD is either `get', `head', `post', `put', or
  3000.      `delete'.  `html:start-form' prints the header for an HTML "form".
  3001.  - Function: html:end-form PNAME SUBMIT-LABEL
  3002.      `html:end-form' prints the footer for an HTML "form".  The string
  3003.      SUBMIT-LABEL appears on the button which submits the form.
  3004.                                                                               |
  3005.  - Function: command->html RDB COMMAND-TABLE COMMAND METHOD ACTION
  3006.      The symbol COMMAND-TABLE names a command table in the RDB
  3007.      relational database.
  3008.      `command->html' writes an HTML-2.0 "form" for command COMMAND to
  3009.      the current-output-port.  The `SUBMIT' button, which is labeled
  3010.      COMMAND, invokes the URI ACTION with method METHOD with a hidden
  3011.      attribute `*command*' bound to the command symbol submitted.
  3012.      An action may invoke a CGI script
  3013.      (`http://www.my-site.edu/cgi-bin/search.cgi') or HTTP daemon
  3014.      (`http://www.my-site.edu:8001').
  3015.      This example demonstrates how to create a HTML-form for the `build'
  3016.      command.
  3017.           (require (in-vicinity (implementation-vicinity) "build.scm"))
  3018.           (call-with-output-file "buildscm.html"
  3019.             (lambda (port)
  3020.               (fluid-let ((*html:output-port* port))
  3021.                 (html:start-page 'commands)
  3022.                 (command->html
  3023.                  build '*commands* 'build 'post
  3024.                  (or "/cgi-bin/build.cgi"
  3025.                      "http://localhost:8081/buildscm"))
  3026.                 html:end-page)))
  3027. HTTP and CGI service
  3028. ====================
  3029.   `(require 'html-form)'
  3030.  - Function: cgi:serve-command RDB COMMAND-TABLE
  3031.      Reads a `"POST"' or `"GET"' query from `(current-input-port)' and
  3032.      executes the encoded command from COMMAND-TABLE in
  3033.      relational-database RDB.
  3034.      This example puts up a plain-text page in response to a CGI query.
  3035.           (display "Content-Type: text/plain") (newline) (newline)
  3036.           (require 'html-form)
  3037.           (load (in-vicinity (implementation-vicinity) "build.scm"))
  3038.           (cgi:serve-command build '*commands*)
  3039.  - Function: serve-urlencoded-command RDB COMMAND-TABLE URLENCODED
  3040.      Reads attribute-value pairs from URLENCODED, converts them to
  3041.      parameters and invokes the RDB command named by the parameter
  3042.      `*command*'.
  3043.  - Function: http:serve-query INPUT-PORT OUTPUT-PORT SERVE-PROC
  3044.      reads the "query-string" from INPUT-PORT.  If this is a valid
  3045.      `"POST"' or `"GET"' query, then `http:serve-query' calls
  3046.      SERVE-PROC with two arguments, the query-string and the
  3047.      header-alist.
  3048.      Otherwise, `http:serve-query' replies (to OUTPUT-PORT) with
  3049.      appropriate HTML describing the problem.
  3050.   This example services HTTP queries from port 8081:
  3051.      (define socket (make-stream-socket AF_INET 0))
  3052.      (socket:bind socket 8081)
  3053.      (socket:listen socket 10)
  3054.      (dynamic-wind
  3055.       (lambda () #f)
  3056.       (lambda ()
  3057.         (do ((port (socket:accept socket)
  3058.                    (socket:accept socket)))
  3059.             (#f)
  3060.           (dynamic-wind
  3061.            (lambda () #f)
  3062.            (lambda ()
  3063.              (fluid-let ((*html:output-port* port))
  3064.                (http:serve-query
  3065.                 port port
  3066.                 (lambda (query-string header)
  3067.                   (http:send-header
  3068.                    '(("Content-Type" . "text/plain")))
  3069.                   (with-output-to-port port
  3070.                     (lambda ()
  3071.                       (serve-urlencoded-command
  3072.                        build '*commands* query-string)))))))
  3073.            (lambda () (close-port port)))))
  3074.       (lambda () (close-port socket)))
  3075.  - Function: http:read-request-line PORT
  3076.      Reads the first non-blank line from PORT and, if successful,
  3077.      returns a list of three itmes from the request-line:
  3078.        0. Method
  3079.           Either one of the symbols `options', `get', `head', `post',
  3080.           `put', `delete', or `trace'; Or a string.
  3081.        1. Request-URI
  3082.           A string.  At the minimum, it will be the string `"/"'.
  3083.        2. HTTP-Version
  3084.           A string.  For example, `HTTP/1.0'.
  3085.  - Function: cgi:read-query-string
  3086.      Reads the "query-string" from `(current-input-port)'.
  3087.      `cgi:read-query-string' reads a `"POST"' or `"GET"' queries,
  3088.      depending on the value of `(getenv "REQUEST_METHOD")'.
  3089. File: slib.info,  Node: Printing Scheme,  Next: Time and Date,  Prev: HTML HTTP and CGI,  Up: Textual Conversion Packages
  3090. Printing Scheme
  3091. ===============
  3092. * Menu:
  3093. * Generic-Write::               'generic-write
  3094. * Object-To-String::            'object->string
  3095. * Pretty-Print::                'pretty-print, 'pprint-file
  3096. File: slib.info,  Node: Generic-Write,  Next: Object-To-String,  Prev: Printing Scheme,  Up: Printing Scheme
  3097. Generic-Write
  3098. -------------
  3099.   `(require 'generic-write)'
  3100.   `generic-write' is a procedure that transforms a Scheme data value
  3101. (or Scheme program expression) into its textual representation and
  3102. prints it.  The interface to the procedure is sufficiently general to
  3103. easily implement other useful formatting procedures such as pretty
  3104. printing, output to a string and truncated output.
  3105.  - Procedure: generic-write OBJ DISPLAY? WIDTH OUTPUT
  3106.     OBJ
  3107.           Scheme data value to transform.
  3108.     DISPLAY?
  3109.           Boolean, controls whether characters and strings are quoted.
  3110.     WIDTH
  3111.           Extended boolean, selects format:
  3112.          #f
  3113.                single line format
  3114.          integer > 0
  3115.                pretty-print (value = max nb of chars per line)
  3116.     OUTPUT
  3117.           Procedure of 1 argument of string type, called repeatedly with
  3118.           successive substrings of the textual representation.  This
  3119.           procedure can return `#f' to stop the transformation.
  3120.      The value returned by `generic-write' is undefined.
  3121.      Examples:
  3122.           (write obj) == (generic-write obj #f #f DISPLAY-STRING)
  3123.           (display obj) == (generic-write obj #t #f DISPLAY-STRING)
  3124.      where
  3125.           DISPLAY-STRING ==
  3126.           (lambda (s) (for-each write-char (string->list s)) #t)
  3127. File: slib.info,  Node: Object-To-String,  Next: Pretty-Print,  Prev: Generic-Write,  Up: Printing Scheme
  3128. Object-To-String
  3129. ----------------
  3130.   `(require 'object->string)'
  3131.  - Function: object->string OBJ
  3132.      Returns the textual representation of OBJ as a string.
  3133.  - Function: object->limited-string OBJ LIMIT
  3134.      Returns the textual representation of OBJ as a string of length at
  3135.      most LIMIT.
  3136. File: slib.info,  Node: Pretty-Print,  Prev: Object-To-String,  Up: Printing Scheme
  3137. Pretty-Print
  3138. ------------
  3139.   `(require 'pretty-print)'
  3140.  - Procedure: pretty-print OBJ
  3141.  - Procedure: pretty-print OBJ PORT
  3142.      `pretty-print's OBJ on PORT.  If PORT is not specified,
  3143.      `current-output-port' is used.
  3144.      Example:
  3145.           (pretty-print '((1 2 3 4 5) (6 7 8 9 10) (11 12 13 14 15)
  3146.                           (16 17 18 19 20) (21 22 23 24 25)))
  3147.              -| ((1 2 3 4 5)
  3148.              -|  (6 7 8 9 10)
  3149.              -|  (11 12 13 14 15)
  3150.              -|  (16 17 18 19 20)
  3151.              -|  (21 22 23 24 25))
  3152.   `(require 'pprint-file)'
  3153.  - Procedure: pprint-file INFILE
  3154.  - Procedure: pprint-file INFILE OUTFILE
  3155.      Pretty-prints all the code in INFILE.  If OUTFILE is specified,
  3156.      the output goes to OUTFILE, otherwise it goes to
  3157.      `(current-output-port)'.
  3158.  - Function: pprint-filter-file INFILE PROC OUTFILE
  3159.  - Function: pprint-filter-file INFILE PROC
  3160.      INFILE is a port or a string naming an existing file.  Scheme
  3161.      source code expressions and definitions are read from the port (or
  3162.      file) and PROC is applied to them sequentially.
  3163.      OUTFILE is a port or a string.  If no OUTFILE is specified then
  3164.      `current-output-port' is assumed.  These expanded expressions are
  3165.      then `pretty-print'ed to this port.
  3166.      Whitepsace and comments (introduced by `;') which are not part of
  3167.      scheme expressions are reproduced in the output.  This procedure
  3168.      does not affect the values returned by `current-input-port' and
  3169.      `current-output-port'.
  3170.   `pprint-filter-file' can be used to pre-compile macro-expansion and
  3171. thus can reduce loading time.  The following will write into
  3172. `exp-code.scm' the result of expanding all defmacros in `code.scm'.
  3173.      (require 'pprint-file)
  3174.      (require 'defmacroexpand)
  3175.      (defmacro:load "my-macros.scm")
  3176.      (pprint-filter-file "code.scm" defmacro:expand* "exp-code.scm")
  3177. File: slib.info,  Node: Time and Date,  Next: Vector Graphics,  Prev: Printing Scheme,  Up: Textual Conversion Packages
  3178. Time and Date
  3179. =============
  3180. * Menu:
  3181. * Time Zone::                                                                 |
  3182. * Posix Time::                  'posix-time
  3183. * Common-Lisp Time::            'common-lisp-time
  3184. If `(provided? 'current-time)':                                               |
  3185.                                                                               |
  3186. The procedures `current-time', `difftime', and `offset-time' deal with        |
  3187. a "calendar time" datatype which may or may not be disjoint from other        |
  3188. Scheme datatypes.                                                             |
  3189.                                                                               |
  3190.  - Function: current-time                                                     |
  3191.      Returns the time since 00:00:00 GMT, January 1, 1970, measured in        |
  3192.      seconds.  Note that the reference time is different from the             |
  3193.      reference time for `get-universal-time' in *Note Common-Lisp
  3194.      Time::.                                                                  |
  3195.                                                                               |
  3196.  - Function: difftime CALTIME1 CALTIME0                                       |
  3197.      Returns the difference (number of seconds) between twe calendar          |
  3198.      times: CALTIME1 - CALTIME0.  CALTIME0 may also be a number.              |
  3199.                                                                               |
  3200.  - Function: offset-time CALTIME OFFSET                                       |
  3201.      Returns the calendar time of CALTIME offset by OFFSET number of          |
  3202.      seconds `(+ caltime offset)'.                                            |
  3203.                                                                               |
  3204. File: slib.info,  Node: Time Zone,  Next: Posix Time,  Prev: Time and Date,  Up: Time and Date
  3205.                                                                               |
  3206. Time Zone                                                                     |
  3207. ---------                                                                     |
  3208.                                                                               |
  3209.   (require 'time-zone)                                                        |
  3210.                                                                               |
  3211.  - Data Format: TZ-string                                                     |
  3212.      POSIX standards specify several formats for encoding time-zone           |
  3213.      rules.                                                                   |
  3214.                                                                               |
  3215.     :<pathname>                                                               |
  3216.           If the first character of <pathname> is `/', then <pathname>        |
  3217.           specifies the absolute pathname of a tzfile(5) format               |
  3218.           time-zone file.  Otherwise, <pathname> is interpreted as a          |
  3219.           pathname within TZFILE:VICINITY (/usr/lib/zoneinfo/) naming a       |
  3220.           tzfile(5) format time-zone file.                                    |
  3221.                                                                               |
  3222.     <std><offset>                                                             |
  3223.           The string <std> consists of 3 or more alphabetic characters.       |
  3224.           <offset> specifies the time difference from GMT.  The <offset>      |
  3225.           is positive if the local time zone is west of the Prime             |
  3226.           Meridian and negative if it is east.  <offset> can be the           |
  3227.           number of hours or hours and minutes (and optionally seconds)       |
  3228.           separated by `:'.  For example, `-4:30'.                            |
  3229.                                                                               |
  3230.     <std><offset><dst>                                                        |
  3231.           <dst> is the at least 3 alphabetic characters naming the local      |
  3232.           daylight-savings-time.                                              |
  3233.                                                                               |
  3234.     <std><offset><dst><doffset>                                               |
  3235.           <doffset> specifies the offset from the Prime Meridian when         |
  3236.           daylight-savings-time is in effect.                                 |
  3237.                                                                               |
  3238.      The non-tzfile formats can optionally be followed by transition          |
  3239.      times specifying the day and time when a zone changes from               |
  3240.      standard to daylight-savings and back again.                             |
  3241.                                                                               |
  3242.     ,<date>/<time>,<date>/<time>                                              |
  3243.           The <time>s are specified like the <offset>s above, except          |
  3244.           that leading `+' and `-' are not allowed.                           |
  3245.                                                                               |
  3246.           Each <date> has one of the formats:                                 |
  3247.                                                                               |
  3248.          J<day>                                                               |
  3249.                specifies the Julian day with <day> between 1 and 365.         |
  3250.                February 29 is never counted and cannot be referenced.         |
  3251.                                                                               |
  3252.          <day>                                                                |
  3253.                This specifies the Julian day with n between 0 and 365.        |
  3254.                February 29 is counted in leap years and can be                |
  3255.                specified.                                                     |
  3256.                                                                               |
  3257.          M<month>.<week>.<day>                                                |
  3258.                This specifies day <day> (0 <= <day> <= 6) of week             |
  3259.                <week> (1 <= <week> <= 5) of month <month> (1 <= <month>       |
  3260.                <= 12).  Week 1 is the first week in which day d occurs        |
  3261.                and week 5 is the last week in which day <day> occurs.         |
  3262.                Day 0 is a Sunday.                                             |
  3263.                                                                               |
  3264.                                                                               |
  3265.  - Data Type: time-zone                                                       |
  3266.      is a datatype encoding how many hours from Greenwich Mean Time the       |
  3267.      local time is, and the "Daylight Savings Time" rules for changing        |
  3268.      it.                                                                      |
  3269.                                                                               |
  3270.  - Function: time-zone TZ-STRING                                              |
  3271.      Creates and returns a time-zone object specified by the string           |
  3272.      TZ-STRING.  If `time-zone' cannot interpret TZ-STRING, `#f' is           |
  3273.      returned.                                                                |
  3274.                                                                               |
  3275.  - Function: tz:params CALTIME TZ                                             |
  3276.      TZ is a time-zone object.  `tz:params' returns a list of three           |
  3277.      items:                                                                   |
  3278.        0. An integer.  0 if standard time is in effect for timezone TZ        |
  3279.           at CALTIME; 1 if daylight savings time is in effect for             |
  3280.           timezone TZ at CALTIME.                                             |
  3281.                                                                               |
  3282.        1. The number of seconds west of the Prime Meridian timezone TZ        |
  3283.           is at CALTIME.                                                      |
  3284.                                                                               |
  3285.        2. The name for timezone TZ at CALTIME.                                |
  3286.                                                                               |
  3287.      `tz:params' is unaffected by the default timezone; inquiries can be      |
  3288.      made of any timezone at any calendar time.                               |
  3289.                                                                               |
  3290.                                                                               |
  3291. The rest of these procedures and variables are provided for POSIX             |
  3292. compatability.  Because of shared state they are not thread-safe.             |
  3293.                                                                               |
  3294.  - Function: tzset                                                            |
  3295.      Returns the default time-zone.                                           |
  3296.                                                                               |
  3297.  - Function: tzset TZ                                                         |
  3298.      Sets (and returns) the default time-zone to TZ.                          |
  3299.                                                                               |
  3300.  - Function: tzset TZ-STRING                                                  |
  3301.      Sets (and returns) the default time-zone to that specified by            |
  3302.      TZ-STRING.                                                               |
  3303.                                                                               |
  3304.      `tzset' also sets the variables *TIMEZONE*, DAYLIGHT?, and TZNAME.       |
  3305.      This function is automatically called by the time conversion             |
  3306.      procedures which depend on the time zone (*note Time and Date::.).       |
  3307.                                                                               |
  3308.  - Variable: *timezone*                                                       |
  3309.      Contains the difference, in seconds, between Greenwich Mean Time         |
  3310.      and local standard time (for example, in the U.S.  Eastern time          |
  3311.      zone (EST), timezone is 5*60*60).  `*timezone*' is initialized by        |
  3312.      `tzset'.                                                                 |
  3313.                                                                               |
  3314.  - Variable: daylight?                                                        |
  3315.      is `#t' if the default timezone has rules for "Daylight Savings          |
  3316.      Time".  *Note:* DAYLIGHT? does not tell you when Daylight Savings        |
  3317.      Time is in effect, just that the default zone sometimes has              |
  3318.      Daylight Savings Time.                                                   |
  3319.                                                                               |
  3320.  - Variable: tzname                                                           |
  3321.      is a vector of strings.  Index 0 has the abbreviation for the            |
  3322.      standard timezone; If DAYLIGHT?, then index 1 has the abbreviation       |
  3323.      for the Daylight Savings timezone.                                       |
  3324.                                                                               |
  3325. File: slib.info,  Node: Posix Time,  Next: Common-Lisp Time,  Prev: Time Zone,  Up: Time and Date
  3326.                                                                               |
  3327. Posix Time
  3328. ----------
  3329.      (require 'posix-time)
  3330.  - Data Type: Calendar-Time
  3331.      is a datatype encapsulating time.
  3332.  - Data Type: Coordinated Universal Time
  3333.      (abbreviated "UTC") is a vector of integers representing time:
  3334.        0.  seconds (0 - 61)
  3335.        1.  minutes (0 - 59)
  3336.        2.  hours since midnight (0 - 23)
  3337.        3.  day of month (1 - 31)
  3338.        4.  month (0 - 11).  Note difference from
  3339.           `decode-universal-time'.
  3340.        5.  the number of years since 1900.  Note difference from
  3341.           `decode-universal-time'.
  3342.        6.  day of week (0 - 6)
  3343.        7.  day of year (0 - 365)
  3344.        8.  1 for daylight savings, 0 for regular time
  3345.  - Function: gmtime CALTIME
  3346.      Converts the calendar time CALTIME to UTC and returns it.
  3347.  - Function: localtime CALTIME TZ
  3348.      Returns CALTIME converted to UTC relative to timezone TZ.
  3349.  - Function: localtime CALTIME
  3350.      converts the calendar time CALTIME to a vector of integers
  3351.      expressed relative to the user's time zone.  `localtime' sets the
  3352.      variable *TIMEZONE* with the difference between Coordinated
  3353.      Universal Time (UTC) and local standard time in seconds (*note
  3354.      tzset: Time Zone.).
  3355.  - Function: gmktime UNIVTIME
  3356.      Converts a vector of integers in GMT Coordinated Universal Time
  3357.      (UTC) format to a calendar time.
  3358.  - Function: mktime UNIVTIME
  3359.      Converts a vector of integers in local Coordinated Universal Time
  3360.      (UTC) format to a calendar time.
  3361.  - Function: mktime UNIVTIME TZ
  3362.      Converts a vector of integers in Coordinated Universal Time (UTC)
  3363.      format (relative to time-zone TZ) to calendar time.
  3364.  - Function: asctime UNIVTIME
  3365.      Converts the vector of integers CALTIME in Coordinated Universal
  3366.      Time (UTC) format into a string of the form `"Wed Jun 30 21:49:08
  3367.      1993"'.
  3368.  - Function: gtime CALTIME
  3369.  - Function: ctime CALTIME
  3370.  - Function: ctime CALTIME TZ
  3371.      Equivalent to `(asctime (gmtime CALTIME))', `(asctime (localtime
  3372.      CALTIME))', and `(asctime (localtime CALTIME TZ))', respectively.
  3373. File: slib.info,  Node: Common-Lisp Time,  Prev: Posix Time,  Up: Time and Date
  3374. Common-Lisp Time
  3375. ----------------
  3376.  - Function: get-decoded-time
  3377.      Equivalent to `(decode-universal-time (get-universal-time))'.
  3378.  - Function: get-universal-time
  3379.      Returns the current time as "Universal Time", number of seconds
  3380.      since 00:00:00 Jan 1, 1900 GMT.  Note that the reference time is
  3381.      different from `current-time'.
  3382.  - Function: decode-universal-time UNIVTIME
  3383.      Converts UNIVTIME to "Decoded Time" format.  Nine values are
  3384.      returned:
  3385.        0.  seconds (0 - 61)
  3386.        1.  minutes (0 - 59)
  3387.        2.  hours since midnight
  3388.        3.  day of month
  3389.        4.  month (1 - 12).  Note difference from `gmtime' and
  3390.           `localtime'.
  3391.        5.  year (A.D.).  Note difference from `gmtime' and `localtime'.
  3392.        6.  day of week (0 - 6)
  3393.        7.  #t for daylight savings, #f otherwise
  3394.        8.  hours west of GMT (-24 - +24)
  3395.      Notice that the values returned by `decode-universal-time' do not
  3396.      match the arguments to `encode-universal-time'.
  3397.  - Function: encode-universal-time SECOND MINUTE HOUR DATE MONTH YEAR
  3398.  - Function: encode-universal-time SECOND MINUTE HOUR DATE MONTH YEAR
  3399.           TIME-ZONE
  3400.      Converts the arguments in Decoded Time format to Universal Time
  3401.      format.  If TIME-ZONE is not specified, the returned time is
  3402.      adjusted for daylight saving time.  Otherwise, no adjustment is
  3403.      performed.
  3404.      Notice that the values returned by `decode-universal-time' do not
  3405.      match the arguments to `encode-universal-time'.
  3406. File: slib.info,  Node: Vector Graphics,  Next: Schmooz,  Prev: Time and Date,  Up: Textual Conversion Packages
  3407. Vector Graphics
  3408. ===============
  3409. * Menu:
  3410. * Tektronix Graphics Support::
  3411. File: slib.info,  Node: Tektronix Graphics Support,  Prev: Vector Graphics,  Up: Vector Graphics
  3412. Tektronix Graphics Support
  3413. --------------------------
  3414.   *Note:* The Tektronix graphics support files need more work, and are
  3415. not complete.
  3416. Tektronix 4000 Series Graphics
  3417. ..............................
  3418.   The Tektronix 4000 series graphics protocol gives the user a 1024 by
  3419. 1024 square drawing area.  The origin is in the lower left corner of the
  3420. screen.  Increasing y is up and increasing x is to the right.
  3421.   The graphics control codes are sent over the current-output-port and
  3422. can be mixed with regular text and ANSI or other terminal control
  3423. sequences.
  3424.  - Procedure: tek40:init
  3425.  - Procedure: tek40:graphics
  3426.  - Procedure: tek40:text
  3427.  - Procedure: tek40:linetype LINETYPE
  3428.  - Procedure: tek40:move X Y
  3429.  - Procedure: tek40:draw X Y
  3430.  - Procedure: tek40:put-text X Y STR
  3431.  - Procedure: tek40:reset
  3432. Tektronix 4100 Series Graphics
  3433. ..............................
  3434.   The graphics control codes are sent over the current-output-port and
  3435. can be mixed with regular text and ANSI or other terminal control
  3436. sequences.
  3437.  - Procedure: tek41:init
  3438.  - Procedure: tek41:reset
  3439.  - Procedure: tek41:graphics
  3440.  - Procedure: tek41:move X Y
  3441.  - Procedure: tek41:draw X Y
  3442.  - Procedure: tek41:point X Y NUMBER
  3443.  - Procedure: tek41:encode-x-y X Y
  3444.  - Procedure: tek41:encode-int NUMBER
  3445. File: slib.info,  Node: Schmooz,  Prev: Vector Graphics,  Up: Textual Conversion Packages
  3446. Schmooz
  3447. =======
  3448.   "Schmooz" is a simple, lightweight markup language for interspersing
  3449. Texinfo documentation with Scheme source code.  Schmooz does not create
  3450. the top level Texinfo file; it creates `txi' files which can be
  3451. imported into the documentation using the Texinfo command `@include'.
  3452.   `(require 'schmooz)' defines the function `schmooz', which is used to
  3453. process files.  Files containing schmooz documentation should not
  3454. contain `(require 'schmooz)'.
  3455.  - Procedure: schmooz FILENAMEscm ...
  3456.      FILENAMEscm should be a string ending with `scm' naming an
  3457.      existing file containing Scheme source code.  `schmooz' extracts
  3458.      top-level comments containing schmooz commands from FILENAMEscm
  3459.      and writes the converted Texinfo source to a file named
  3460.      FILENAMEtxi.
  3461.  - Procedure: schmooz FILENAMEtexi ...
  3462.  - Procedure: schmooz FILENAMEtex ...
  3463.  - Procedure: schmooz FILENAMEtxi ...
  3464.      FILENAME should be a string naming an existing file containing
  3465.      Texinfo source code.  For every occurrence of the string `@include
  3466.      FILENAMEtxi' within that file, `schmooz' calls itself with the
  3467.      argument `FILENAMEscm'.
  3468.   Schmooz comments are distinguished (from non-schmooz comments) by
  3469. their first line, which must start with an at-sign (@) preceded by one
  3470. or more semicolons (;).  A schmooz comment ends at the first subsequent
  3471. line which does *not* start with a semicolon.  Currently schmooz
  3472. comments are recognized only at top level.
  3473.   Schmooz comments are copied to the Texinfo output file with the
  3474. leading contiguous semicolons removed.  Certain character sequences
  3475. starting with at-sign are treated specially.  Others are copied
  3476. unchanged.
  3477.   A schmooz comment starting with `@body' must be followed by a Scheme
  3478. definition.  All comments between the `@body' line and the definition
  3479. will be included in a Texinfo definition, either a `@defun' or a
  3480. `@defvar', depending on whether a procedure or a variable is being
  3481. defined.
  3482.   Within the text of that schmooz comment, at-sign followed by `0' will
  3483. be replaced by `@code{procedure-name}' if the following definition is
  3484. of a procedure; or `@var{variable}' if defining a variable.
  3485.   An at-sign followed by a non-zero digit will expand to the variable
  3486. citation of that numbered argument: `@var{argument-name}'.
  3487.   If more than one definition follows a `@body' comment line without an
  3488. intervening blank or comment line, then those definitions will be
  3489. included in the same Texinfo definition using `@defvarx' or `@defunx',
  3490. depending on whether the first definition is of a variable or of a
  3491. procedure.
  3492.   Schmooz can figure out whether a definition is of a procedure if it
  3493. is of the form:
  3494.   `(define (<identifier> <arg> ...) <expression>)'
  3495. or if the left hand side of the definition is some form ending in a
  3496. lambda expression.  Obviously, it can be fooled.  In order to force
  3497. recognition of a procedure definition, start the documentation with
  3498. `@args' instead of `@body'.  `@args' should be followed by the argument
  3499. list of the function being defined, which may be enclosed in
  3500. parentheses and delimited by whitespace, (as in Scheme), enclosed in
  3501. braces and separated by commas, (as in Texinfo), or consist of the
  3502. remainder of the line, separated by whitespace.
  3503.   For example:
  3504.      ;;@args arg1 args ...
  3505.      ;;@0 takes argument @1 and any number of @2
  3506.      (define myfun (some-function-returning-magic))
  3507.   Will result in:
  3508.      @defun myfun arg1 args @dots{}
  3509.      
  3510.      @code{myfun} takes argument @var{arg1} and any number of @var{args}
  3511.      @end defun
  3512.   `@args' may also be useful for indicating optional arguments by name.
  3513. If `@args' occurs inside a schmooz comment section, rather than at the
  3514. beginning, then it will generate a `@defunx' line with the arguments
  3515. supplied.
  3516.   If the first at-sign in a schmooz comment is immediately followed by
  3517. whitespace, then the comment will be expanded to whatever follows that
  3518. whitespace.  If the at-sign is followed by a non-whitespace character
  3519. then the at-sign will be included as the first character of the
  3520. expansion.  This feature is intended to make it easy to include Texinfo
  3521. directives in schmooz comments.
  3522. File: slib.info,  Node: Mathematical Packages,  Next: Database Packages,  Prev: Textual Conversion Packages,  Up: Top
  3523. Mathematical Packages
  3524. *********************
  3525. * Menu:
  3526. * Bit-Twiddling::               'logical
  3527. * Modular Arithmetic::          'modular
  3528. * Prime Numbers::               'factor
  3529. * Random Numbers::              'random
  3530. * Cyclic Checksum::             'make-crc
  3531. * Plotting::                    'charplot
  3532. * Root Finding::                'root
  3533. * Commutative Rings::           'commutative-ring
  3534. * Determinant::                 'determinant
  3535. File: slib.info,  Node: Bit-Twiddling,  Next: Modular Arithmetic,  Prev: Mathematical Packages,  Up: Mathematical Packages
  3536. Bit-Twiddling
  3537. =============
  3538.   `(require 'logical)'
  3539.   The bit-twiddling functions are made available through the use of the
  3540. `logical' package.  `logical' is loaded by inserting `(require
  3541. 'logical)' before the code that uses these functions.  These functions
  3542. behave as though operating on integers in two's-complement
  3543. representation.
  3544. Bitwise Operations
  3545. ------------------
  3546.  - Function: logand N1 N1
  3547.      Returns the integer which is the bit-wise AND of the two integer
  3548.      arguments.
  3549.      Example:
  3550.           (number->string (logand #b1100 #b1010) 2)
  3551.              => "1000"
  3552.  - Function: logior N1 N2
  3553.      Returns the integer which is the bit-wise OR of the two integer
  3554.      arguments.
  3555.      Example:
  3556.           (number->string (logior #b1100 #b1010) 2)
  3557.              => "1110"
  3558.  - Function: logxor N1 N2
  3559.      Returns the integer which is the bit-wise XOR of the two integer
  3560.      arguments.
  3561.      Example:
  3562.           (number->string (logxor #b1100 #b1010) 2)
  3563.              => "110"
  3564.  - Function: lognot N
  3565.      Returns the integer which is the 2s-complement of the integer
  3566.      argument.
  3567.      Example:
  3568.           (number->string (lognot #b10000000) 2)
  3569.              => "-10000001"
  3570.           (number->string (lognot #b0) 2)
  3571.              => "-1"
  3572.  - Function: bitwise-if MASK N0 N1
  3573.      Returns an integer composed of some bits from integer N0 and some
  3574.      from integer N1.  A bit of the result is taken from N0 if the
  3575.      corresponding bit of integer MASK is 1 and from N1 if that bit of
  3576.      MASK is 0.
  3577.  - Function: logtest J K
  3578.           (logtest j k) == (not (zero? (logand j k)))
  3579.           
  3580.           (logtest #b0100 #b1011) => #f
  3581.           (logtest #b0100 #b0111) => #t
  3582.  - Function: logcount N
  3583.      Returns the number of bits in integer N.  If integer is positive,
  3584.      the 1-bits in its binary representation are counted.  If negative,
  3585.      the 0-bits in its two's-complement binary representation are
  3586.      counted.  If 0, 0 is returned.
  3587.      Example:
  3588.           (logcount #b10101010)
  3589.              => 4
  3590.           (logcount 0)
  3591.              => 0
  3592.           (logcount -2)
  3593.              => 1
  3594. Bit Within Word
  3595. ---------------
  3596.  - Function: logbit? INDEX J
  3597.           (logbit? index j) == (logtest (integer-expt 2 index) j)
  3598.           
  3599.           (logbit? 0 #b1101) => #t
  3600.           (logbit? 1 #b1101) => #f
  3601.           (logbit? 2 #b1101) => #t
  3602.           (logbit? 3 #b1101) => #t
  3603.           (logbit? 4 #b1101) => #f
  3604.  - Function: copy-bit INDEX FROM BIT
  3605.      Returns an integer the same as FROM except in the INDEXth bit,
  3606.      which is 1 if BIT is `#t' and 0 if BIT is `#f'.
  3607.      Example:
  3608.           (number->string (copy-bit 0 0 #t) 2)       => "1"
  3609.           (number->string (copy-bit 2 0 #t) 2)       => "100"
  3610.           (number->string (copy-bit 2 #b1111 #f) 2)  => "1011"
  3611. Fields of Bits
  3612. --------------
  3613.  - Function: bit-field N START END
  3614.      Returns the integer composed of the START (inclusive) through END
  3615.      (exclusive) bits of N.  The STARTth bit becomes the 0-th bit in
  3616.      the result.
  3617.      This function was called `bit-extract' in previous versions of
  3618.      SLIB.
  3619.      Example:
  3620.           (number->string (bit-field #b1101101010 0 4) 2)
  3621.              => "1010"
  3622.           (number->string (bit-field #b1101101010 4 9) 2)
  3623.              => "10110"
  3624.  - Function: copy-bit-field TO START END FROM
  3625.      Returns an integer the same as TO except possibly in the START
  3626.      (inclusive) through END (exclusive) bits, which are the same as
  3627.      those of FROM.  The 0-th bit of FROM becomes the STARTth bit of
  3628.      the result.
  3629.      Example:
  3630.           (number->string (copy-bit-field #b1101101010 0 4 0) 2)
  3631.                   => "1101100000"
  3632.           (number->string (copy-bit-field #b1101101010 0 4 -1) 2)
  3633.                   => "1101101111"
  3634.  - Function: ash INT COUNT
  3635.      Returns an integer equivalent to `(inexact->exact (floor (* INT
  3636.      (expt 2 COUNT))))'.
  3637.      Example:
  3638.           (number->string (ash #b1 3) 2)
  3639.              => "1000"
  3640.           (number->string (ash #b1010 -1) 2)
  3641.              => "101"
  3642.  - Function: integer-length N
  3643.      Returns the number of bits neccessary to represent N.
  3644.      Example:
  3645.           (integer-length #b10101010)
  3646.              => 8
  3647.           (integer-length 0)
  3648.              => 0
  3649.           (integer-length #b1111)
  3650.              => 4
  3651.  - Function: integer-expt N K
  3652.      Returns N raised to the non-negative integer exponent K.
  3653.      Example:
  3654.           (integer-expt 2 5)
  3655.              => 32
  3656.           (integer-expt -3 3)
  3657.              => -27
  3658. File: slib.info,  Node: Modular Arithmetic,  Next: Prime Numbers,  Prev: Bit-Twiddling,  Up: Mathematical Packages
  3659. Modular Arithmetic
  3660. ==================
  3661.   `(require 'modular)'
  3662.  - Function: extended-euclid N1 N2
  3663.      Returns a list of 3 integers `(d x y)' such that d = gcd(N1, N2) =
  3664.      N1 * x + N2 * y.
  3665.  - Function: symmetric:modulus N
  3666.      Returns `(quotient (+ -1 n) -2)' for positive odd integer N.
  3667.  - Function: modulus->integer MODULUS
  3668.      Returns the non-negative integer characteristic of the ring formed
  3669.      when MODULUS is used with `modular:' procedures.
  3670.  - Function: modular:normalize MODULUS N
  3671.      Returns the integer `(modulo N (modulus->integer MODULUS))' in the
  3672.      representation specified by MODULUS.
  3673. The rest of these functions assume normalized arguments; That is, the
  3674. arguments are constrained by the following table:
  3675. For all of these functions, if the first argument (MODULUS) is:
  3676. `positive?'
  3677.      Work as before.  The result is between 0 and MODULUS.
  3678. `zero?'
  3679.      The arguments are treated as integers.  An integer is returned.
  3680. `negative?'
  3681.      The arguments and result are treated as members of the integers
  3682.      modulo `(+ 1 (* -2 MODULUS))', but with "symmetric"
  3683.      representation; i.e. `(<= (- MODULUS) N MODULUS)'.
  3684. If all the arguments are fixnums the computation will use only fixnums.
  3685.  - Function: modular:invertable? MODULUS K
  3686.      Returns `#t' if there exists an integer n such that K * n == 1 mod
  3687.      MODULUS, and `#f' otherwise.
  3688.  - Function: modular:invert MODULUS K2
  3689.      Returns an integer n such that 1 = (n * K2) mod MODULUS.  If K2
  3690.      has no inverse mod MODULUS an error is signaled.
  3691.  - Function: modular:negate MODULUS K2
  3692.      Returns (-K2) mod MODULUS.
  3693.  - Function: modular:+ MODULUS K2 K3
  3694.      Returns (K2 + K3) mod MODULUS.
  3695.  - Function: modular:- MODULUS K2 K3
  3696.      Returns (K2 - K3) mod MODULUS.
  3697.  - Function: modular:* MODULUS K2 K3
  3698.      Returns (K2 * K3) mod MODULUS.
  3699.      The Scheme code for `modular:*' with negative MODULUS is not
  3700.      completed for fixnum-only implementations.
  3701.  - Function: modular:expt MODULUS K2 K3
  3702.      Returns (K2 ^ K3) mod MODULUS.
  3703. File: slib.info,  Node: Prime Numbers,  Next: Random Numbers,  Prev: Modular Arithmetic,  Up: Mathematical Packages
  3704. Prime Numbers
  3705. =============
  3706.   `(require 'factor)'
  3707.  - Variable: prime:prngs
  3708.      PRIME:PRNGS is the random-state (*note Random Numbers::.) used by
  3709.      these  procedures.  If you call these procedures from more than
  3710.      one thread  (or from interrupt), `random' may complain about
  3711.      reentrant  calls.
  3712.  - Function: jacobi-symbol P Q
  3713.      Returns the value (+1, -1, or 0) of the Jacobi-Symbol of  exact
  3714.      non-negative integer P and exact positive odd integer Q.
  3715.  - Variable: prime:trials
  3716.      PRIME:TRIALS the maxinum number of iterations of Solovay-Strassen
  3717.      that will  be done to test a number for primality.
  3718.  - Function: prime? N
  3719.      Returns `#f' if N is composite; `#t' if N is prime.   There is a
  3720.      slight chance `(expt 2 (- prime:trials))' that a  composite will
  3721.      return `#t'.
  3722.  - Function: primes< START COUNT
  3723.      Returns a list of the first COUNT prime numbers less than  START.
  3724.      If there are fewer than COUNT prime numbers  less than START, then
  3725.      the returned list will have fewer than  START elements.
  3726.  - Function: primes> START COUNT
  3727.      Returns a list of the first COUNT prime numbers greater than START.
  3728.  - Function: factor K
  3729.      Returns a list of the prime factors of K.  The order of the
  3730.      factors is unspecified.  In order to obtain a sorted list do
  3731.      `(sort! (factor K) <)'.
  3732. File: slib.info,  Node: Random Numbers,  Next: Cyclic Checksum,  Prev: Prime Numbers,  Up: Mathematical Packages
  3733. Random Numbers
  3734. ==============
  3735.   `(require 'random)'
  3736.   A pseudo-random number generator is only as good as the tests it
  3737. passes.  George Marsaglia of Florida State University developed a
  3738. battery of tests named "DIEHARD"
  3739. (`http://stat.fsu.edu/~geo/diehard.html').  `diehard.c' has a bug which
  3740. the patch `ftp://swissnet.ai.mit.edu/pub/users/jaffer/diehard.c.pat'
  3741. corrects.
  3742.   SLIB's new PRNG generates 8 bits at a time.  With the degenerate seed
  3743. `0', the numbers generated pass DIEHARD; but when bits are combined
  3744. from sequential bytes, tests fail.  With the seed
  3745. `http://swissnet.ai.mit.edu/~jaffer/SLIB.html', all of those tests pass.
  3746.  - Function: random N                                                         |
  3747.  - Function: random N STATE                                                   |
  3748.      Accepts a positive integer or real N and returns a number of the
  3749.      same type between zero (inclusive) and N (exclusive).  The values
  3750.      returned by `random' are uniformly distributed from 0 to N.              |
  3751.      The optional argument STATE must be of the type returned by              |
  3752.      `(seed->random-state)' or `(make-random-state)'.  It defaults to         |
  3753.      the value of the variable `*random-state*'.  This object is used         |
  3754.      to maintain the state of the pseudo-random-number generator and is       |
  3755.      altered as a side effect of calls to `random'.                           |
  3756.  - Variable: *random-state*
  3757.      Holds a data structure that encodes the internal state of the
  3758.      random-number generator that `random' uses by default.  The nature
  3759.      of this data structure is implementation-dependent.  It may be
  3760.      printed out and successfully read back in, but may or may not
  3761.      function correctly as a random-number state object in another
  3762.      implementation.
  3763.  - Function: copy-random-state STATE                                          |
  3764.      Returns a new copy of argument STATE.                                    |
  3765.                                                                               |
  3766.  - Function: copy-random-state                                                |
  3767.      Returns a new copy of `*random-state*'.                                  |
  3768.                                                                               |
  3769.  - Function: seed->random-state SEED                                          |
  3770.      Returns a new object of type suitable for use as the value of the        |
  3771.      variable `*random-state*' or as a second argument to `random'.           |
  3772.      The number or string SEED is used to initialize the state.  If           |
  3773.      `seed->random-state' is called twice with arguments which are            |
  3774.      `equal?', then the returned data structures will be `equal?'.            |
  3775.      Calling `seed->random-state' with unequal arguments will nearly          |
  3776.      always return unequal states.                                            |
  3777.                                                                               |
  3778.  - Function: make-random-state                                                |
  3779.  - Function: make-random-state OBJ                                            |
  3780.      Returns a new object of type suitable for use as the value of the
  3781.      variable `*random-state*' or as a second argument to `random'.  If       |
  3782.      the optional argument OBJ is given, it should be a printable             |
  3783.      Scheme object; the first 50 characters of its printed                    |
  3784.      representation will be used as the seed.  Otherwise the value of         |
  3785.      `*random-state*' is used as the seed.                                    |
  3786.   If inexact numbers are supported by the Scheme implementation,
  3787. `randinex.scm' will be loaded as well.  `randinex.scm' contains
  3788. procedures for generating inexact distributions.
  3789.  - Function: random:uniform                                                   |
  3790.  - Function: random:uniform STATE                                             |
  3791.      Returns an uniformly distributed inexact real random number in the
  3792.      range between 0 and 1.
  3793.  - Function: random:exp                                                       |
  3794.  - Function: random:exp STATE                                                 |
  3795.      Returns an inexact real in an exponential distribution with mean         |
  3796.      1.  For an exponential distribution with mean U use                      |
  3797.      `(* U (random:exp))'.                                                    |
  3798.                                                                               |
  3799.  - Function: random:normal                                                    |
  3800.  - Function: random:normal STATE                                              |
  3801.      Returns an inexact real in a normal distribution with mean 0 and         |
  3802.      standard deviation 1.  For a normal distribution with mean M and         |
  3803.      standard deviation D use `(+ M (* D (random:normal)))'.                  |
  3804.                                                                               |
  3805.  - Function: random:normal-vector! VECT                                       |
  3806.  - Function: random:normal-vector! VECT STATE                                 |
  3807.      Fills VECT with inexact real random numbers which are independent        |
  3808.      and standard normally distributed (i.e., with mean 0 and variance        |
  3809.      1).                                                                      |
  3810.                                                                               |
  3811.  - Function: random:hollow-sphere! VECT                                       |
  3812.  - Function: random:hollow-sphere! VECT STATE                                 |
  3813.      Fills VECT with inexact real random numbers the sum of whose
  3814.      squares is less than 1.0.  Thinking of VECT as coordinates in
  3815.      space of dimension N = `(vector-length VECT)', the coordinates are
  3816.      uniformly distributed within the unit N-shere.  The sum of the
  3817.      squares of the numbers is returned.
  3818.  - Function: random:solid-sphere! VECT                                        |
  3819.  - Function: random:solid-sphere! VECT STATE                                  |
  3820.      Fills VECT with inexact real random numbers the sum of whose
  3821.      squares is equal to 1.0.  Thinking of VECT as coordinates in space
  3822.      of dimension n = `(vector-length VECT)', the coordinates are
  3823.      uniformly distributed over the surface of the unit n-shere.
  3824.                                                                               |
  3825. File: slib.info,  Node: Cyclic Checksum,  Next: Plotting,  Prev: Random Numbers,  Up: Mathematical Packages
  3826. Cyclic Checksum
  3827. ===============
  3828.   `(require 'make-crc)'
  3829.  - Function: make-port-crc
  3830.  - Function: make-port-crc DEGREE
  3831.  - Function: make-port-crc DEGREE GENERATOR
  3832.      Returns an expression for a procedure of one argument, a port.
  3833.      This procedure reads characters from the port until the end of
  3834.      file and returns the integer checksum of the bytes read.
  3835.      The integer DEGREE, if given, specifies the degree of the
  3836.      polynomial being computed - which is also the number of bits
  3837.      computed in the checksums.  The default value is 32.
  3838.      The integer GENERATOR specifies the polynomial being computed.
  3839.      The power of 2 generating each 1 bit is the exponent of a term of
  3840.      the polynomial.  The bit at position DEGREE is implicit and should
  3841.      not be part of GENERATOR.  This allows systems with numbers
  3842.      limited to 32 bits to calculate 32 bit checksums.  The default
  3843.      value of GENERATOR when DEGREE is 32 (its default) is:
  3844.           (make-port-crc 32 #b00000100110000010001110110110111)
  3845.      Creates a procedure to calculate the P1003.2/D11.2 (POSIX.2) 32-bit
  3846.      checksum from the polynomial:
  3847.                32    26    23    22    16    12    11
  3848.             ( x   + x   + x   + x   + x   + x   + x   +
  3849.           
  3850.                 10    8    7    5    4    2    1
  3851.                x   + x  + x  + x  + x  + x  + x  + 1 )  mod 2
  3852.      (require 'make-crc)
  3853.      (define crc32 (slib:eval (make-port-crc)))
  3854.      (define (file-check-sum file) (call-with-input-file file crc32))
  3855.      (file-check-sum (in-vicinity (library-vicinity) "ratize.scm"))
  3856.      
  3857.      => 3553047446
  3858. File: slib.info,  Node: Plotting,  Next: Root Finding,  Prev: Cyclic Checksum,  Up: Mathematical Packages
  3859. Plotting on Character Devices
  3860. =============================
  3861.   `(require 'charplot)'
  3862.   The plotting procedure is made available through the use of the
  3863. `charplot' package.  `charplot' is loaded by inserting `(require
  3864. 'charplot)' before the code that uses this procedure.
  3865.  - Variable: charplot:height
  3866.      The number of rows to make the plot vertically.
  3867.  - Variable: charplot:width
  3868.      The number of columns to make the plot horizontally.
  3869.  - Procedure: plot! COORDS X-LABEL Y-LABEL
  3870.      COORDS is a list of pairs of x and y coordinates.  X-LABEL and
  3871.      Y-LABEL are strings with which to label the x and y axes.
  3872.      Example:
  3873.           (require 'charplot)
  3874.           (set! charplot:height 19)
  3875.           (set! charplot:width 45)
  3876.           
  3877.           (define (make-points n)
  3878.             (if (zero? n)
  3879.                 '()
  3880.                 (cons (cons (/ n 6) (sin (/ n 6))) (make-points (1- n)))))
  3881.           
  3882.           (plot! (make-points 37) "x" "Sin(x)")
  3883.           -|
  3884.             Sin(x)   ______________________________________________
  3885.                 1.25|-                                             |
  3886.                     |                                              |
  3887.                    1|-       ****                                  |
  3888.                     |      **    **                                |
  3889.             750.0e-3|-    *        *                               |
  3890.                     |    *          *                              |
  3891.             500.0e-3|-  *            *                             |
  3892.                     |  *                                           |
  3893.             250.0e-3|-                *                            |
  3894.                     | *                *                           |
  3895.                    0|-------------------*--------------------------|
  3896.                     |                                     *        |
  3897.            -250.0e-3|-                   *               *         |
  3898.                     |                     *             *          |
  3899.            -500.0e-3|-                     *                       |
  3900.                     |                       *          *           |
  3901.            -750.0e-3|-                       *        *            |
  3902.                     |                         **    **             |
  3903.                   -1|-                          ****               |
  3904.                     |____________:_____._____:_____._____:_________|
  3905.                   x              2           4
  3906. File: slib.info,  Node: Root Finding,  Next: Commutative Rings,  Prev: Plotting,  Up: Mathematical Packages
  3907. Root Finding
  3908. ============
  3909.   `(require 'root)'
  3910.  - Function: newtown:find-integer-root F DF/DX X0
  3911.      Given integer valued procedure F, its derivative (with respect to
  3912.      its argument) DF/DX, and initial integer value X0 for which
  3913.      DF/DX(X0) is non-zero, returns an integer X for which F(X) is
  3914.      closer to zero than either of the integers adjacent to X; or
  3915.      returns `#f' if such an integer can't be found.
  3916.      To find the closest integer to a given integers square root:
  3917.           (define (integer-sqrt y)
  3918.             (newton:find-integer-root
  3919.              (lambda (x) (- (* x x) y))
  3920.              (lambda (x) (* 2 x))
  3921.              (ash 1 (quotient (integer-length y) 2))))
  3922.           
  3923.           (integer-sqrt 15) => 4
  3924.  - Function: integer-sqrt Y
  3925.      Given a non-negative integer Y, returns the rounded square-root of
  3926.      Y.
  3927.  - Function: newton:find-root F DF/DX X0 PREC
  3928.      Given real valued procedures F, DF/DX of one (real) argument,
  3929.      initial real value X0 for which DF/DX(X0) is non-zero, and
  3930.      positive real number PREC, returns a real X for which `abs'(F(X))
  3931.      is less than PREC; or returns `#f' if such a real can't be found.
  3932.      If PREC is instead a negative integer, `newton:find-root' returns        |
  3933.      the result of -PREC iterations.                                          |
  3934. H. J. Orchard, `The Laguerre Method for Finding the Zeros of
  3935. Polynomials', IEEE Transactions on Circuits and Systems, Vol. 36, No.
  3936. 11, November 1989, pp 1377-1381.
  3937.      There are 2 errors in Orchard's Table II.  Line k=2 for starting
  3938.      value of 1000+j0 should have Z_k of 1.0475 + j4.1036 and line k=2
  3939.      for starting value of 0+j1000 should have Z_k of 1.0988 + j4.0833.
  3940.  - Function: laguerre:find-root F DF/DZ DDF/DZ^2 Z0 PREC
  3941.      Given complex valued procedure F of one (complex) argument, its
  3942.      derivative (with respect to its argument) DF/DX, its second
  3943.      derivative DDF/DZ^2, initial complex value Z0, and positive real
  3944.      number PREC, returns a complex number Z for which
  3945.      `magnitude'(F(Z)) is less than PREC; or returns `#f' if such a
  3946.      number can't be found.
  3947.      If PREC is instead a negative integer, `laguerre:find-root'              |
  3948.      returns the result of -PREC iterations.
  3949.  - Function: laguerre:find-polynomial-root DEG F DF/DZ DDF/DZ^2 Z0 PREC
  3950.      Given polynomial procedure F of integer degree DEG of one
  3951.      argument, its derivative (with respect to its argument) DF/DX, its
  3952.      second derivative DDF/DZ^2, initial complex value Z0, and positive
  3953.      real number PREC, returns a complex number Z for which
  3954.      `magnitude'(F(Z)) is less than PREC; or returns `#f' if such a
  3955.      number can't be found.
  3956.      If PREC is instead a negative integer,                                   |
  3957.      `laguerre:find-polynomial-root' returns the result of -PREC
  3958.      iterations.
  3959.  - Function: secant:find-root F X0 X1 PREC                                    |
  3960.  - Function: secant:find-bracketed-root F X0 X1 PREC                          |
  3961.      Given a real valued procedure F and two real valued starting             |
  3962.      points X0 and X1, returns a real X for which `(abs (f x))' is less       |
  3963.      than PREC; or returns `#f' if such a real can't be found.                |
  3964.                                                                               |
  3965.      If X0 and X1 are chosen such that they bracket a root, that is           |
  3966.           (or (< (f x0) 0 (f x1))                                             |
  3967.               (< (f x1) 0 (f x0)))                                            |
  3968.      then the root returned will be between X0 and X1, and F will not         |
  3969.      be passed an argument outside of that interval.                          |
  3970.                                                                               |
  3971.      `secant:find-bracketed-root' will return `#f' unless X0 and X1           |
  3972.      bracket a root.                                                          |
  3973.                                                                               |
  3974.      The secant or regula falsi method will be used unless a bracketing       |
  3975.      interval has been found and the secant method is not making              |
  3976.      sufficient progress, in which case bisection of the interval will        |
  3977.      be used.                                                                 |
  3978.                                                                               |
  3979.      If PREC is instead a negative integer, `secant:find-root' returns        |
  3980.      the result of -PREC iterations.                                          |
  3981.                                                                               |
  3982.      If PREC is a procedure it should accept 5 arguments: X0 F0 X1 F1         |
  3983.      and COUNT, where F0 will be `(f x0)', F1 `(f x1)', and COUNT the         |
  3984.      number of iterations performed so far.  PREC should return               |
  3985.      non-false if the iteration should be stopped.                            |
  3986.                                                                               |
  3987. File: slib.info,  Node: Commutative Rings,  Next: Determinant,  Prev: Root Finding,  Up: Mathematical Packages
  3988. Commutative Rings
  3989. =================
  3990.   Scheme provides a consistent and capable set of numeric functions.
  3991. Inexacts implement a field; integers a commutative ring (and Euclidean
  3992. domain).  This package allows one to use basic Scheme numeric functions
  3993. with symbols and non-numeric elements of commutative rings.
  3994.   `(require 'commutative-ring)'
  3995.   The "commutative-ring" package makes the procedures `+', `-', `*',
  3996. `/', and `^' "careful" in the sense that any non-numeric arguments they
  3997. do not reduce appear in the expression output.  In order to see what
  3998. working with this package is like, self-set all the single letter
  3999. identifiers (to their corresponding symbols).
  4000.      (define a 'a)
  4001.      ...
  4002.      (define z 'z)
  4003.   Or just `(require 'self-set)'.  Now try some sample expressions:
  4004.      (+ (+ a b) (- a b)) => (* a 2)
  4005.      (* (+ a b) (+ a b)) => (^ (+ a b) 2)
  4006.      (* (+ a b) (- a b)) => (* (+ a b) (- a b))
  4007.      (* (- a b) (- a b)) => (^ (- a b) 2)
  4008.      (* (- a b) (+ a b)) => (* (+ a b) (- a b))
  4009.      (/ (+ a b) (+ c d)) => (/ (+ a b) (+ c d))
  4010.      (^ (+ a b) 3) => (^ (+ a b) 3)
  4011.      (^ (+ a 2) 3) => (^ (+ 2 a) 3)
  4012.   Associative rules have been applied and repeated addition and
  4013. multiplication converted to multiplication and exponentiation.
  4014.   We can enable distributive rules, thus expanding to sum of products
  4015. form:
  4016.      (set! *ruleset* (combined-rulesets distribute* distribute/))
  4017.      
  4018.      (* (+ a b) (+ a b)) => (+ (* 2 a b) (^ a 2) (^ b 2))
  4019.      (* (+ a b) (- a b)) => (- (^ a 2) (^ b 2))
  4020.      (* (- a b) (- a b)) => (- (+ (^ a 2) (^ b 2)) (* 2 a b))
  4021.      (* (- a b) (+ a b)) => (- (^ a 2) (^ b 2))
  4022.      (/ (+ a b) (+ c d)) => (+ (/ a (+ c d)) (/ b (+ c d)))
  4023.      (/ (+ a b) (- c d)) => (+ (/ a (- c d)) (/ b (- c d)))
  4024.      (/ (- a b) (- c d)) => (- (/ a (- c d)) (/ b (- c d)))
  4025.      (/ (- a b) (+ c d)) => (- (/ a (+ c d)) (/ b (+ c d)))
  4026.      (^ (+ a b) 3) => (+ (* 3 a (^ b 2)) (* 3 b (^ a 2)) (^ a 3) (^ b 3))
  4027.      (^ (+ a 2) 3) => (+ 8 (* a 12) (* (^ a 2) 6) (^ a 3))
  4028.   Use of this package is not restricted to simple arithmetic
  4029. expressions:
  4030.      (require 'determinant)
  4031.      
  4032.      (determinant '((a b c) (d e f) (g h i))) =>
  4033.      (- (+ (* a e i) (* b f g) (* c d h)) (* a f h) (* b d i) (* c e g))
  4034.   Currently, only `+', `-', `*', `/', and `^' support non-numeric
  4035. elements.  Expressions with `-' are converted to equivalent expressions
  4036. without `-', so behavior for `-' is not defined separately.  `/'
  4037. expressions are handled similarly.
  4038.   This list might be extended to include `quotient', `modulo',
  4039. `remainder', `lcm', and `gcd'; but these work only for the more
  4040. restrictive Euclidean (Unique Factorization) Domain.
  4041. Rules and Rulesets
  4042. ==================
  4043.   The "commutative-ring" package allows control of ring properties
  4044. through the use of "rulesets".
  4045.  - Variable: *ruleset*
  4046.      Contains the set of rules currently in effect.  Rules defined by
  4047.      `cring:define-rule' are stored within the value of *ruleset* at the
  4048.      time `cring:define-rule' is called.  If *RULESET* is `#f', then no
  4049.      rules apply.
  4050.  - Function: make-ruleset RULE1 ...
  4051.  - Function: make-ruleset NAME RULE1 ...
  4052.      Returns a new ruleset containing the rules formed by applying
  4053.      `cring:define-rule' to each 4-element list argument RULE.  If the
  4054.      first argument to `make-ruleset' is a symbol, then the database
  4055.      table created for the new ruleset will be named NAME.  Calling
  4056.      `make-ruleset' with no rule arguments creates an empty ruleset.
  4057.  - Function: combined-rulesets RULESET1 ...
  4058.  - Function: combined-rulesets NAME RULESET1 ...
  4059.      Returns a new ruleset containing the rules contained in each
  4060.      ruleset argument RULESET.  If the first argument to
  4061.      `combined-ruleset' is a symbol, then the database table created for
  4062.      the new ruleset will be named NAME.  Calling `combined-ruleset'
  4063.      with no ruleset arguments creates an empty ruleset.
  4064.   Two rulesets are defined by this package.
  4065.  - Constant: distribute*
  4066.      Contain the ruleset to distribute multiplication over addition and
  4067.      subtraction.
  4068.  - Constant: distribute/
  4069.      Contain the ruleset to distribute division over addition and
  4070.      subtraction.
  4071.      Take care when using both DISTRIBUTE* and DISTRIBUTE/
  4072.      simultaneously.  It is possible to put `/' into an infinite loop.
  4073.   You can specify how sum and product expressions containing non-numeric
  4074. elements simplify by specifying the rules for `+' or `*' for cases
  4075. where expressions involving objects reduce to numbers or to expressions
  4076. involving different non-numeric elements.
  4077.  - Function: cring:define-rule OP SUB-OP1 SUB-OP2 REDUCTION
  4078.      Defines a rule for the case when the operation represented by
  4079.      symbol OP is applied to lists whose `car's are SUB-OP1 and
  4080.      SUB-OP2, respectively.  The argument REDUCTION is a procedure
  4081.      accepting 2 arguments which will be lists whose `car's are SUB-OP1
  4082.      and SUB-OP2.
  4083.  - Function: cring:define-rule OP SUB-OP1 'IDENTITY REDUCTION
  4084.      Defines a rule for the case when the operation represented by
  4085.      symbol OP is applied to a list whose `car' is SUB-OP1, and some
  4086.      other argument.  REDUCTION will be called with the list whose
  4087.      `car' is SUB-OP1 and some other argument.
  4088.      If REDUCTION returns `#f', the reduction has failed and other
  4089.      reductions will be tried.  If REDUCTION returns a non-false value,
  4090.      that value will replace the two arguments in arithmetic (`+', `-',
  4091.      and `*') calculations involving non-numeric elements.
  4092.      The operations `+' and `*' are assumed commutative; hence both
  4093.      orders of arguments to REDUCTION will be tried if necessary.
  4094.      The following rule is the definition for distributing `*' over `+'.
  4095.           (cring:define-rule
  4096.            '* '+ 'identity
  4097.            (lambda (exp1 exp2)
  4098.              (apply + (map (lambda (trm) (* trm exp2)) (cdr exp1))))))
  4099. How to Create a Commutative Ring
  4100. ================================
  4101.   The first step in creating your commutative ring is to write
  4102. procedures to create elements of the ring.  A non-numeric element of
  4103. the ring must be represented as a list whose first element is a symbol
  4104. or string.  This first element identifies the type of the object.  A
  4105. convenient and clear convention is to make the type-identifying element
  4106. be the same symbol whose top-level value is the procedure to create it.
  4107.      (define (n . list1)
  4108.        (cond ((and (= 2 (length list1))
  4109.                    (eq? (car list1) (cadr list1)))
  4110.               0)
  4111.              ((not (term< (first list1) (last1 list1)))
  4112.               (apply n (reverse list1)))
  4113.              (else (cons 'n list1))))
  4114.      
  4115.      (define (s x y) (n x y))
  4116.      
  4117.      (define (m . list1)
  4118.        (cond ((neq? (first list1) (term_min list1))
  4119.               (apply m (cyclicrotate list1)))
  4120.              ((term< (last1 list1) (cadr list1))
  4121.               (apply m (reverse (cyclicrotate list1))))
  4122.              (else (cons 'm list1))))
  4123.   Define a procedure to multiply 2 non-numeric elements of the ring.
  4124. Other multiplicatons are handled automatically.  Objects for which rules
  4125. have *not* been defined are not changed.
  4126.      (define (n*n ni nj)
  4127.        (let ((list1 (cdr ni)) (list2 (cdr nj)))
  4128.          (cond ((null? (intersection list1 list2)) #f)
  4129.                ((and (eq? (last1 list1) (first list2))
  4130.                      (neq? (first list1) (last1 list2)))
  4131.                 (apply n (splice list1 list2)))
  4132.                ((and (eq? (first list1) (first list2))
  4133.                      (neq? (last1 list1) (last1 list2)))
  4134.                 (apply n (splice (reverse list1) list2)))
  4135.                ((and (eq? (last1 list1) (last1 list2))
  4136.                      (neq? (first list1) (first list2)))
  4137.                 (apply n (splice list1 (reverse list2))))
  4138.                ((and (eq? (last1 list1) (first list2))
  4139.                      (eq? (first list1) (last1 list2)))
  4140.                 (apply m (cyclicsplice list1 list2)))
  4141.                ((and (eq? (first list1) (first list2))
  4142.                      (eq? (last1 list1) (last1 list2)))
  4143.                 (apply m (cyclicsplice (reverse list1) list2)))
  4144.                (else #f))))
  4145.   Test the procedures to see if they work.
  4146.      ;;; where cyclicrotate(list) is cyclic rotation of the list one step
  4147.      ;;; by putting the first element at the end
  4148.      (define (cyclicrotate list1)
  4149.        (append (rest list1) (list (first list1))))
  4150.      ;;; and where term_min(list) is the element of the list which is
  4151.      ;;; first in the term ordering.
  4152.      (define (term_min list1)
  4153.        (car (sort list1 term<)))
  4154.      (define (term< sym1 sym2)
  4155.        (string<? (symbol->string sym1) (symbol->string sym2)))
  4156.      (define first car)
  4157.      (define rest cdr)
  4158.      (define (last1 list1) (car (last-pair list1)))
  4159.      (define (neq? obj1 obj2) (not (eq? obj1 obj2)))
  4160.      ;;; where splice is the concatenation of list1 and list2 except that their
  4161.      ;;; common element is not repeated.
  4162.      (define (splice list1 list2)
  4163.        (cond ((eq? (last1 list1) (first list2))
  4164.               (append list1 (cdr list2)))
  4165.              (else (error 'splice list1 list2))))
  4166.      ;;; where cyclicsplice is the result of leaving off the last element of
  4167.      ;;; splice(list1,list2).
  4168.      (define (cyclicsplice list1 list2)
  4169.        (cond ((and (eq? (last1 list1) (first list2))
  4170.                    (eq? (first list1) (last1 list2)))
  4171.               (butlast (splice list1 list2) 1))
  4172.              (else (error 'cyclicsplice list1 list2))))
  4173.      
  4174.      (N*N (S a b) (S a b)) => (m a b)
  4175.   Then register the rule for multiplying type N objects by type N
  4176. objects.
  4177.      (cring:define-rule '* 'N 'N N*N))
  4178.   Now we are ready to compute!
  4179.      (define (t)
  4180.        (define detM
  4181.          (+ (* (S g b)
  4182.                (+ (* (S f d)
  4183.                      (- (* (S a f) (S d g)) (* (S a g) (S d f))))
  4184.                   (* (S f f)
  4185.                      (- (* (S a g) (S d d)) (* (S a d) (S d g))))
  4186.                   (* (S f g)
  4187.                      (- (* (S a d) (S d f)) (* (S a f) (S d d))))))
  4188.             (* (S g d)
  4189.                (+ (* (S f b)
  4190.                      (- (* (S a g) (S d f)) (* (S a f) (S d g))))
  4191.                   (* (S f f)
  4192.                      (- (* (S a b) (S d g)) (* (S a g) (S d b))))
  4193.                   (* (S f g)
  4194.                      (- (* (S a f) (S d b)) (* (S a b) (S d f))))))
  4195.             (* (S g f)
  4196.                (+ (* (S f b)
  4197.                      (- (* (S a d) (S d g)) (* (S a g) (S d d))))
  4198.                   (* (S f d)
  4199.                      (- (* (S a g) (S d b)) (* (S a b) (S d g))))
  4200.                   (* (S f g)
  4201.                      (- (* (S a b) (S d d)) (* (S a d) (S d b))))))
  4202.             (* (S g g)
  4203.                (+ (* (S f b)
  4204.                      (- (* (S a f) (S d d)) (* (S a d) (S d f))))
  4205.                   (* (S f d)
  4206.                      (- (* (S a b) (S d f)) (* (S a f) (S d b))))
  4207.                   (* (S f f)
  4208.                      (- (* (S a d) (S d b)) (* (S a b) (S d d))))))))
  4209.        (* (S b e) (S c a) (S e c)
  4210.           detM
  4211.           ))
  4212.      (pretty-print (t))
  4213.      -|
  4214.      (- (+ (m a c e b d f g)
  4215.            (m a c e b d g f)
  4216.            (m a c e b f d g)
  4217.            (m a c e b f g d)
  4218.            (m a c e b g d f)
  4219.            (m a c e b g f d))
  4220.         (* 2 (m a b e c) (m d f g))
  4221.         (* (m a c e b d) (m f g))
  4222.         (* (m a c e b f) (m d g))
  4223.         (* (m a c e b g) (m d f)))
  4224. File: slib.info,  Node: Determinant,  Prev: Commutative Rings,  Up: Mathematical Packages
  4225. Determinant
  4226. ===========
  4227.      (require 'determinant)
  4228.      (determinant '((1 2) (3 4))) => -2
  4229.      (determinant '((1 2 3) (4 5 6) (7 8 9))) => 0
  4230.      (determinant '((1 2 3 4) (5 6 7 8) (9 10 11 12))) => 0
  4231. File: slib.info,  Node: Database Packages,  Next: Other Packages,  Prev: Mathematical Packages,  Up: Top
  4232. Database Packages
  4233. *****************
  4234. * Menu:
  4235. * Base Table::
  4236. * Relational Database::         'relational-database
  4237. * Weight-Balanced Trees::       'wt-tree
  4238. File: slib.info,  Node: Base Table,  Next: Relational Database,  Prev: Database Packages,  Up: Database Packages
  4239. Base Table
  4240. ==========
  4241.   A base table implementation using Scheme association lists is
  4242. available as the value of the identifier `alist-table' after doing:
  4243.   `(require 'alist-table)'
  4244.   Association list base tables are suitable for small databases and
  4245. support all Scheme types when temporary and readable/writeable Scheme
  4246. types when saved.  I hope support for other base table implementations
  4247. will be added in the future.
  4248.   This rest of this section documents the interface for a base table
  4249. implementation from which the *Note Relational Database:: package
  4250. constructs a Relational system.  It will be of interest primarily to
  4251. those wishing to port or write new base-table implementations.
  4252.   All of these functions are accessed through a single procedure by
  4253. calling that procedure with the symbol name of the operation.  A
  4254. procedure will be returned if that operation is supported and `#f'
  4255. otherwise.  For example:
  4256.      (require 'alist-table)
  4257.      (define open-base (alist-table 'make-base))
  4258.      make-base       => *a procedure*
  4259.      (define foo (alist-table 'foo))
  4260.      foo             => #f
  4261.  - Function: make-base FILENAME KEY-DIMENSION COLUMN-TYPES
  4262.      Returns a new, open, low-level database (collection of tables)
  4263.      associated with FILENAME.  This returned database has an empty
  4264.      table associated with CATALOG-ID.  The positive integer
  4265.      KEY-DIMENSION is the number of keys composed to make a PRIMARY-KEY
  4266.      for the catalog table.  The list of symbols COLUMN-TYPES describes
  4267.      the types of each column for that table.  If the database cannot
  4268.      be created as specified, `#f' is returned.
  4269.      Calling the `close-base' method on this database and possibly other
  4270.      operations will cause FILENAME to be written to.  If FILENAME is
  4271.      `#f' a temporary, non-disk based database will be created if such
  4272.      can be supported by the base table implelentation.
  4273.  - Function: open-base FILENAME MUTABLE
  4274.      Returns an open low-level database associated with FILENAME.  If
  4275.      MUTABLE? is `#t', this database will have methods capable of
  4276.      effecting change to the database.  If MUTABLE? is `#f', only
  4277.      methods for inquiring the database will be available.  If the
  4278.      database cannot be opened as specified `#f' is returned.
  4279.      Calling the `close-base' (and possibly other) method on a MUTABLE?
  4280.      database will cause FILENAME to be written to.
  4281.  - Function: write-base LLDB FILENAME
  4282.      Causes the low-level database LLDB to be written to FILENAME.  If
  4283.      the write is successful, also causes LLDB to henceforth be
  4284.      associated with FILENAME.  Calling the `close-database' (and
  4285.      possibly other) method on LLDB may cause FILENAME to be written
  4286.      to.  If FILENAME is `#f' this database will be changed to a
  4287.      temporary, non-disk based database if such can be supported by the
  4288.      underlying base table implelentation.  If the operations completed
  4289.      successfully, `#t' is returned.  Otherwise, `#f' is returned.
  4290.  - Function: sync-base LLDB
  4291.      Causes the file associated with the low-level database LLDB to be
  4292.      updated to reflect its current state.  If the associated filename
  4293.      is `#f', no action is taken and `#f' is returned.  If this
  4294.      operation completes successfully, `#t' is returned.  Otherwise,
  4295.      `#f' is returned.
  4296.  - Function: close-base LLDB
  4297.      Causes the low-level database LLDB to be written to its associated
  4298.      file (if any).  If the write is successful, subsequent operations
  4299.      to LLDB will signal an error.  If the operations complete
  4300.      successfully, `#t' is returned.  Otherwise, `#f' is returned.
  4301.  - Function: make-table LLDB KEY-DIMENSION COLUMN-TYPES
  4302.      Returns the BASE-ID for a new base table, otherwise returns `#f'.
  4303.      The base table can then be opened using `(open-table LLDB
  4304.      BASE-ID)'.  The positive integer KEY-DIMENSION is the number of
  4305.      keys composed to make a PRIMARY-KEY for this table.  The list of
  4306.      symbols COLUMN-TYPES describes the types of each column.
  4307.  - Constant: catalog-id
  4308.      A constant BASE-ID suitable for passing as a parameter to
  4309.      `open-table'.  CATALOG-ID will be used as the base table for the
  4310.      system catalog.
  4311.  - Function: open-table LLDB BASE-ID KEY-DIMENSION COLUMN-TYPES
  4312.      Returns a HANDLE for an existing base table in the low-level
  4313.      database LLDB if that table exists and can be opened in the mode
  4314.      indicated by MUTABLE?, otherwise returns `#f'.
  4315.      As with `make-table', the positive integer KEY-DIMENSION is the
  4316.      number of keys composed to make a PRIMARY-KEY for this table.  The
  4317.      list of symbols COLUMN-TYPES describes the types of each column.
  4318.  - Function: kill-table LLDB BASE-ID KEY-DIMENSION COLUMN-TYPES
  4319.      Returns `#t' if the base table associated with BASE-ID was removed
  4320.      from the low level database LLDB, and `#f' otherwise.
  4321.  - Function: make-keyifier-1 TYPE
  4322.      Returns a procedure which accepts a single argument which must be
  4323.      of type TYPE.  This returned procedure returns an object suitable
  4324.      for being a KEY argument in the functions whose descriptions
  4325.      follow.
  4326.      Any 2 arguments of the supported type passed to the returned
  4327.      function which are not `equal?' must result in returned values
  4328.      which are not `equal?'.
  4329.  - Function: make-list-keyifier KEY-DIMENSION TYPES
  4330.      The list of symbols TYPES must have at least KEY-DIMENSION
  4331.      elements.  Returns a procedure which accepts a list of length
  4332.      KEY-DIMENSION and whose types must corresopond to the types named
  4333.      by TYPES.  This returned procedure combines the elements of its
  4334.      list argument into an object suitable for being a KEY argument in
  4335.      the functions whose descriptions follow.
  4336.      Any 2 lists of supported types (which must at least include
  4337.      symbols and non-negative integers) passed to the returned function
  4338.      which are not `equal?' must result in returned values which are not
  4339.      `equal?'.
  4340.  - Function: make-key-extractor KEY-DIMENSION TYPES COLUMN-NUMBER
  4341.      Returns a procedure which accepts objects produced by application
  4342.      of the result of `(make-list-keyifier KEY-DIMENSION TYPES)'.  This
  4343.      procedure returns a KEY which is `equal?' to the COLUMN-NUMBERth
  4344.      element of the list which was passed to create COMBINED-KEY.  The
  4345.      list TYPES must have at least KEY-DIMENSION elements.
  4346.  - Function: make-key->list KEY-DIMENSION TYPES
  4347.      Returns a procedure which accepts objects produced by application
  4348.      of the result of `(make-list-keyifier KEY-DIMENSION TYPES)'.  This
  4349.      procedure returns a list of KEYs which are elementwise `equal?' to
  4350.      the list which was passed to create COMBINED-KEY.
  4351. In the following functions, the KEY argument can always be assumed to
  4352. be the value returned by a call to a *keyify* routine.
  4353. In contrast, a MATCH-KEY argument is a list of length equal to the
  4354. number of primary keys.  The  MATCH-KEY restricts the actions of the
  4355. table command to those records whose primary keys all satisfy the
  4356. corresponding element of the MATCH-KEY list.  The elements and their
  4357. actions are:
  4358.     `#f'
  4359.           The false value matches any key in the corresponding position.
  4360.     an object of type procedure
  4361.           This procedure must take a single argument, the key in the
  4362.           corresponding position.  Any key for which the procedure
  4363.           returns a non-false value is a match; Any key for which the
  4364.           procedure returns a `#f' is not.
  4365.     other values
  4366.           Any other value matches only those keys `equal?' to it.
  4367.  - Function: for-each-key HANDLE PROCEDURE MATCH-KEY
  4368.      Calls PROCEDURE once with each KEY in the table opened in HANDLE
  4369.      which satisfies MATCH-KEY in an unspecified order.  An unspecified
  4370.      value is returned.
  4371.  - Function: map-key HANDLE PROCEDURE MATCH-KEY
  4372.      Returns a list of the values returned by calling PROCEDURE once
  4373.      with each KEY in the table opened in HANDLE which satisfies
  4374.      MATCH-KEY in an unspecified order.
  4375.  - Function: ordered-for-each-key HANDLE PROCEDURE MATCH-KEY
  4376.      Calls PROCEDURE once with each KEY in the table opened in HANDLE
  4377.      which satisfies MATCH-KEY in the natural order for the types of
  4378.      the primary key fields of that table.  An unspecified value is
  4379.      returned.
  4380.  - Function: delete* HANDLE MATCH-KEY
  4381.      Removes all rows which satisfy MATCH-KEY from the table opened in
  4382.      HANDLE.  An unspecified value is returned.
  4383.  - Function: present? HANDLE KEY
  4384.      Returns a non-`#f' value if there is a row associated with KEY in
  4385.      the table opened in HANDLE and `#f' otherwise.
  4386.  - Function: delete HANDLE KEY
  4387.      Removes the row associated with KEY from the table opened in
  4388.      HANDLE.  An unspecified value is returned.
  4389.  - Function: make-getter KEY-DIMENSION TYPES
  4390.      Returns a procedure which takes arguments HANDLE and KEY.  This
  4391.      procedure returns a list of the non-primary values of the relation
  4392.      (in the base table opened in HANDLE) whose primary key is KEY if
  4393.      it exists, and `#f' otherwise.
  4394.  - Function: make-putter KEY-DIMENSION TYPES
  4395.      Returns a procedure which takes arguments HANDLE and KEY and
  4396.      VALUE-LIST.  This procedure associates the primary key KEY with
  4397.      the values in VALUE-LIST (in the base table opened in HANDLE) and
  4398.      returns an unspecified value.
  4399.  - Function: supported-type? SYMBOL
  4400.      Returns `#t' if SYMBOL names a type allowed as a column value by
  4401.      the implementation, and `#f' otherwise.  At a minimum, an
  4402.      implementation must support the types `integer', `symbol',
  4403.      `string', `boolean', and `base-id'.
  4404.  - Function: supported-key-type? SYMBOL
  4405.      Returns `#t' if SYMBOL names a type allowed as a key value by the
  4406.      implementation, and `#f' otherwise.  At a minimum, an
  4407.      implementation must support the types `integer', and `symbol'.
  4408. `integer'
  4409.      Scheme exact integer.
  4410. `symbol'
  4411.      Scheme symbol.
  4412. `boolean'
  4413.      `#t' or `#f'.
  4414. `base-id'
  4415.      Objects suitable for passing as the BASE-ID parameter to
  4416.      `open-table'.  The value of CATALOG-ID must be an acceptable
  4417.      `base-id'.
  4418. File: slib.info,  Node: Relational Database,  Next: Weight-Balanced Trees,  Prev: Base Table,  Up: Database Packages
  4419. Relational Database
  4420. ===================
  4421.   `(require 'relational-database)'
  4422.   This package implements a database system inspired by the Relational
  4423. Model (`E. F. Codd, A Relational Model of Data for Large Shared Data
  4424. Banks').  An SLIB relational database implementation can be created
  4425. from any *Note Base Table:: implementation.
  4426. * Menu:
  4427. * Motivations::                 Database Manifesto
  4428. * Creating and Opening Relational Databases::
  4429. * Relational Database Operations::
  4430. * Table Operations::
  4431. * Catalog Representation::
  4432. * Unresolved Issues::
  4433. * Database Utilities::          'database-utilities
  4434. * Database Reports::
  4435. * Database Browser::            'database-browse
  4436. File: slib.info,  Node: Motivations,  Next: Creating and Opening Relational Databases,  Prev: Relational Database,  Up: Relational Database
  4437. Motivations
  4438. -----------
  4439.   Most nontrivial programs contain databases: Makefiles, configure
  4440. scripts, file backup, calendars, editors, source revision control, CAD
  4441. systems, display managers, menu GUIs, games, parsers, debuggers,
  4442. profilers, and even error reporting are all rife with databases.  Coding
  4443. databases is such a common activity in programming that many may not be
  4444. aware of how often they do it.
  4445.   A database often starts as a dispatch in a program.  The author,
  4446. perhaps because of the need to make the dispatch configurable, the need
  4447. for correlating dispatch in other routines, or because of changes or
  4448. growth, devises a data structure to contain the information, a routine
  4449. for interpreting that data structure, and perhaps routines for
  4450. augmenting and modifying the stored data.  The dispatch must be
  4451. converted into this form and tested.
  4452.   The programmer may need to devise an interactive program for enabling
  4453. easy examination and modification of the information contained in this
  4454. database.  Often, in an attempt to foster modularity and avoid delays in
  4455. release, intermediate file formats for the database information are
  4456. devised.  It often turns out that users prefer modifying these
  4457. intermediate files with a text editor to using the interactive program
  4458. in order to do operations (such as global changes) not forseen by the
  4459. program's author.
  4460.   In order to address this need, the conscientious software engineer may
  4461. even provide a scripting language to allow users to make repetitive
  4462. database changes.  Users will grumble that they need to read a large
  4463. manual and learn yet another programming language (even if it *almost*
  4464. has language "xyz" syntax) in order to do simple configuration.
  4465.   All of these facilities need to be designed, coded, debugged,
  4466. documented, and supported; often causing what was very simple in concept
  4467. to become a major developement project.
  4468.   This view of databases just outlined is somewhat the reverse of the
  4469. view of the originators of the "Relational Model" of database
  4470. abstraction.  The relational model was devised to unify and allow
  4471. interoperation of large multi-user databases running on diverse
  4472. platforms.  A fairly general purpose "Comprehensive Language" for
  4473. database manipulations is mandated (but not specified) as part of the
  4474. relational model for databases.
  4475.   One aspect of the Relational Model of some importance is that the
  4476. "Comprehensive Language" must be expressible in some form which can be
  4477. stored in the database.  This frees the programmer from having to make
  4478. programs data-driven in order to use a database.
  4479.   This package includes as one of its basic supported types Scheme
  4480. "expression"s.  This type allows expressions as defined by the Scheme
  4481. standards to be stored in the database.  Using `slib:eval' retrieved
  4482. expressions can be evaluated (in the top-level environment).  Scheme's
  4483. `lambda' facilitates closure of environments, modularity, etc. so that
  4484. procedures (which could not be stored directly most databases) can
  4485. still be effectively retrieved.  Since `slib:eval' evaluates
  4486. expressions in the top-level environment, built-in and user defined
  4487. procedures can be easily accessed by name.
  4488.   This package's purpose is to standardize (through a common interface)
  4489. database creation and usage in Scheme programs.  The relational model's
  4490. provision for inclusion of language expressions as data as well as the
  4491. description (in tables, of course) of all of its tables assures that
  4492. relational databases are powerful enough to assume the roles currently
  4493. played by thousands of ad-hoc routines and data formats.
  4494. Such standardization to a relational-like model brings many benefits:
  4495.    * Tables, fields, domains, and types can be dealt with by name in
  4496.      programs.
  4497.    * The underlying database implementation can be changed (for
  4498.      performance or other reasons) by changing a single line of code.
  4499.    * The formats of tables can be easily extended or changed without
  4500.      altering code.
  4501.    * Consistency checks are specified as part of the table descriptions.
  4502.      Changes in checks need only occur in one place.
  4503.    * All the configuration information which the developer wishes to
  4504.      group together is easily grouped, without needing to change
  4505.      programs aware of only some of these tables.
  4506.    * Generalized report generators, interactive entry programs, and
  4507.      other database utilities can be part of a shared library.  The
  4508.      burden of adding configurability to a program is greatly reduced.
  4509.    * Scheme is the "comprehensive language" for these databases.
  4510.      Scripting for configuration no longer needs to be in a separate
  4511.      language with additional documentation.
  4512.    * Scheme's latent types mesh well with the strict typing and logical
  4513.      requirements of the relational model.
  4514.    * Portable formats allow easy interchange of data.  The included
  4515.      table descriptions help prevent misinterpretation of format.
  4516. File: slib.info,  Node: Creating and Opening Relational Databases,  Next: Relational Database Operations,  Prev: Motivations,  Up: Relational Database
  4517. Creating and Opening Relational Databases
  4518. -----------------------------------------
  4519.  - Function: make-relational-system BASE-TABLE-IMPLEMENTATION
  4520.      Returns a procedure implementing a relational database using the
  4521.      BASE-TABLE-IMPLEMENTATION.
  4522.      All of the operations of a base table implementation are accessed
  4523.      through a procedure defined by `require'ing that implementation.
  4524.      Similarly, all of the operations of the relational database
  4525.      implementation are accessed through the procedure returned by
  4526.      `make-relational-system'.  For instance, a new relational database
  4527.      could be created from the procedure returned by
  4528.      `make-relational-system' by:
  4529.           (require 'alist-table)
  4530.           (define relational-alist-system
  4531.                   (make-relational-system alist-table))
  4532.           (define create-alist-database
  4533.                   (relational-alist-system 'create-database))
  4534.           (define my-database
  4535.                   (create-alist-database "mydata.db"))
  4536. What follows are the descriptions of the methods available from
  4537. relational system returned by a call to `make-relational-system'.
  4538.  - Function: create-database FILENAME
  4539.      Returns an open, nearly empty relational database associated with
  4540.      FILENAME.  The only tables defined are the system catalog and
  4541.      domain table.  Calling the `close-database' method on this database
  4542.      and possibly other operations will cause FILENAME to be written
  4543.      to.  If FILENAME is `#f' a temporary, non-disk based database will
  4544.      be created if such can be supported by the underlying base table
  4545.      implelentation.  If the database cannot be created as specified
  4546.      `#f' is returned.  For the fields and layout of descriptor tables,
  4547.      *Note Catalog Representation::
  4548.  - Function: open-database FILENAME MUTABLE?
  4549.      Returns an open relational database associated with FILENAME.  If
  4550.      MUTABLE? is `#t', this database will have methods capable of
  4551.      effecting change to the database.  If MUTABLE? is `#f', only
  4552.      methods for inquiring the database will be available.  Calling the
  4553.      `close-database' (and possibly other) method on a MUTABLE?
  4554.      database will cause FILENAME to be written to.  If the database
  4555.      cannot be opened as specified `#f' is returned.
  4556. File: slib.info,  Node: Relational Database Operations,  Next: Table Operations,  Prev: Creating and Opening Relational Databases,  Up: Relational Database
  4557. Relational Database Operations
  4558. ------------------------------
  4559. These are the descriptions of the methods available from an open
  4560. relational database.  A method is retrieved from a database by calling
  4561. the database with the symbol name of the operation.  For example:
  4562.      (define my-database
  4563.              (create-alist-database "mydata.db"))
  4564.      (define telephone-table-desc
  4565.              ((my-database 'create-table) 'telephone-table-desc))
  4566.  - Function: close-database
  4567.      Causes the relational database to be written to its associated
  4568.      file (if any).  If the write is successful, subsequent operations
  4569.      to this database will signal an error.  If the operations completed
  4570.      successfully, `#t' is returned.  Otherwise, `#f' is returned.
  4571.  - Function: write-database FILENAME
  4572.      Causes the relational database to be written to FILENAME.  If the
  4573.      write is successful, also causes the database to henceforth be
  4574.      associated with FILENAME.  Calling the `close-database' (and
  4575.      possibly other) method on this database will cause FILENAME to be
  4576.      written to.  If FILENAME is `#f' this database will be changed to
  4577.      a temporary, non-disk based database if such can be supported by
  4578.      the underlying base table implelentation.  If the operations
  4579.      completed successfully, `#t' is returned.  Otherwise, `#f' is
  4580.      returned.
  4581.  - Function: table-exists? TABLE-NAME
  4582.      Returns `#t' if TABLE-NAME exists in the system catalog, otherwise
  4583.      returns `#f'.
  4584.  - Function: open-table TABLE-NAME MUTABLE?
  4585.      Returns a "methods" procedure for an existing relational table in
  4586.      this database if it exists and can be opened in the mode indicated
  4587.      by MUTABLE?, otherwise returns `#f'.
  4588. These methods will be present only in databases which are MUTABLE?.
  4589.  - Function: delete-table TABLE-NAME
  4590.      Removes and returns the TABLE-NAME row from the system catalog if
  4591.      the table or view associated with TABLE-NAME gets removed from the
  4592.      database, and `#f' otherwise.
  4593.  - Function: create-table TABLE-DESC-NAME
  4594.      Returns a methods procedure for a new (open) relational table for
  4595.      describing the columns of a new base table in this database,
  4596.      otherwise returns `#f'.  For the fields and layout of descriptor
  4597.      tables, *Note Catalog Representation::.
  4598.  - Function: create-table TABLE-NAME TABLE-DESC-NAME
  4599.      Returns a methods procedure for a new (open) relational table with
  4600.      columns as described by TABLE-DESC-NAME, otherwise returns `#f'.
  4601.  - Function: create-view ??
  4602.  - Function: project-table ??
  4603.  - Function: restrict-table ??
  4604.  - Function: cart-prod-tables ??
  4605.      Not yet implemented.
  4606. File: slib.info,  Node: Table Operations,  Next: Catalog Representation,  Prev: Relational Database Operations,  Up: Relational Database
  4607. Table Operations
  4608. ----------------
  4609. These are the descriptions of the methods available from an open
  4610. relational table.  A method is retrieved from a table by calling the
  4611. table with the symbol name of the operation.  For example:
  4612.      (define telephone-table-desc
  4613.              ((my-database 'create-table) 'telephone-table-desc))
  4614.      (require 'common-list-functions)
  4615.      (define ndrp (telephone-table-desc 'row:insert))
  4616.      (ndrp '(1 #t name #f string))
  4617.      (ndrp '(2 #f telephone
  4618.                (lambda (d)
  4619.                  (and (string? d) (> (string-length d) 2)
  4620.                       (every
  4621.                        (lambda (c)
  4622.                          (memv c '(#\0 #\1 #\2 #\3 #\4 #\5 #\6 #\7 #\8 #\9
  4623.                                        #\+ #\( #\  #\) #\-)))
  4624.                        (string->list d))))
  4625.                string))
  4626. Some operations described below require primary key arguments.  Primary
  4627. keys arguments are denoted KEY1 KEY2 ....  It is an error to call an
  4628. operation for a table which takes primary key arguments with the wrong
  4629. number of primary keys for that table.
  4630. The term "row" used below refers to a Scheme list of values (one for
  4631. each column) in the order specified in the descriptor (table) for this
  4632. table.  Missing values appear as `#f'.  Primary keys must not be
  4633. missing.
  4634.  - Function: get COLUMN-NAME
  4635.      Returns a procedure of arguments KEY1 KEY2 ... which returns the
  4636.      value for the COLUMN-NAME column of the row associated with
  4637.      primary keys KEY1, KEY2 ... if that row exists in the table, or
  4638.      `#f' otherwise.
  4639.           ((plat 'get 'processor) 'djgpp) => i386
  4640.           ((plat 'get 'processor) 'be-os) => #f
  4641.  - Function: get* COLUMN-NAME
  4642.      Returns a procedure of optional arguments MATCH-KEY1 ... which
  4643.      returns a list of the values for the specified column for all rows
  4644.      in this table.  The optional MATCH-KEY1 ... arguments restrict
  4645.      actions to a subset of the table.  See the match-key description
  4646.      below for details.
  4647.           ((plat 'get* 'processor)) =>
  4648.           (i386 8086 i386 8086 i386 i386 8086 m68000
  4649.            m68000 m68000 m68000 m68000 powerpc)
  4650.           
  4651.           ((plat 'get* 'processor) #f) =>
  4652.           (i386 8086 i386 8086 i386 i386 8086 m68000
  4653.            m68000 m68000 m68000 m68000 powerpc)
  4654.           
  4655.           (define (a-key? key)
  4656.              (char=? #\a (string-ref (symbol->string key) 0)))
  4657.           
  4658.           ((plat 'get* 'processor) a-key?) =>
  4659.           (m68000 m68000 m68000 m68000 m68000 powerpc)
  4660.           
  4661.           ((plat 'get* 'name) a-key?) =>
  4662.           (atari-st-turbo-c atari-st-gcc amiga-sas/c-5.10
  4663.            amiga-aztec amiga-dice-c aix)
  4664.  - Function: row:retrieve
  4665.      Returns a procedure of arguments KEY1 KEY2 ... which returns the
  4666.      row associated with primary keys KEY1, KEY2 ... if it exists, or
  4667.      `#f' otherwise.
  4668.           ((plat 'row:retrieve) 'linux) => (linux i386 linux gcc)
  4669.           ((plat 'row:retrieve) 'multics) => #f
  4670.  - Function: row:retrieve*
  4671.      Returns a procedure of optional arguments MATCH-KEY1 ... which
  4672.      returns a list of all rows in this table.  The optional MATCH-KEY1
  4673.      ... arguments restrict actions to a subset of the table.  See the
  4674.      match-key description below for details.
  4675.      ((plat 'row:retrieve*) a-key?) =>
  4676.      ((atari-st-turbo-c m68000 atari turbo-c)
  4677.       (atari-st-gcc m68000 atari gcc)
  4678.       (amiga-sas/c-5.10 m68000 amiga sas/c)
  4679.       (amiga-aztec m68000 amiga aztec)
  4680.       (amiga-dice-c m68000 amiga dice-c)
  4681.       (aix powerpc aix -))
  4682.  - Function: row:remove
  4683.      Returns a procedure of arguments KEY1 KEY2 ... which removes and
  4684.      returns the row associated with primary keys KEY1, KEY2 ... if it
  4685.      exists, or `#f' otherwise.
  4686.  - Function: row:remove*
  4687.      Returns a procedure of optional arguments MATCH-KEY1 ... which
  4688.      removes and returns a list of all rows in this table.  The optional
  4689.      MATCH-KEY1 ... arguments restrict actions to a subset of the
  4690.      table.  See the match-key description below for details.
  4691.  - Function: row:delete
  4692.      Returns a procedure of arguments KEY1 KEY2 ... which deletes the
  4693.      row associated with primary keys KEY1, KEY2 ... if it exists.  The
  4694.      value returned is unspecified.
  4695.  - Function: row:delete*
  4696.      Returns a procedure of optional arguments MATCH-KEY1 ... which
  4697.      Deletes all rows from this table.  The optional MATCH-KEY1 ...
  4698.      arguments restrict deletions to a subset of the table.  See the
  4699.      match-key description below for details.  The value returned is
  4700.      unspecified.  The descriptor table and catalog entry for this
  4701.      table are not affected.
  4702.  - Function: row:update
  4703.      Returns a procedure of one argument, ROW, which adds the row, ROW,
  4704.      to this table.  If a row for the primary key(s) specified by ROW
  4705.      already exists in this table, it will be overwritten.  The value
  4706.      returned is unspecified.
  4707.  - Function: row:update*
  4708.      Returns a procedure of one argument, ROWS, which adds each row in
  4709.      the list of rows, ROWS, to this table.  If a row for the primary
  4710.      key specified by an element of ROWS already exists in this table,
  4711.      it will be overwritten.  The value returned is unspecified.
  4712.  - Function: row:insert
  4713.      Adds the row ROW to this table.  If a row for the primary key(s)
  4714.      specified by ROW already exists in this table an error is
  4715.      signaled.  The value returned is unspecified.
  4716.  - Function: row:insert*
  4717.      Returns a procedure of one argument, ROWS, which adds each row in
  4718.      the list of rows, ROWS, to this table.  If a row for the primary
  4719.      key specified by an element of ROWS already exists in this table,
  4720.      an error is signaled.  The value returned is unspecified.
  4721.  - Function: for-each-row
  4722.      Returns a procedure of arguments PROC MATCH-KEY1 ...  which calls
  4723.      PROC with each ROW in this table in the (implementation-dependent)
  4724.      natural ordering for rows.  The optional MATCH-KEY1 ... arguments
  4725.      restrict actions to a subset of the table.  See the match-key
  4726.      description below for details.
  4727.      *Real* relational programmers would use some least-upper-bound join
  4728.      for every row to get them in order; But we don't have joins yet.
  4729. The (optional) MATCH-KEY1 ... arguments are used to restrict actions of
  4730. a whole-table operation to a subset of that table.  Those procedures
  4731. (returned by methods) which accept match-key arguments will accept any
  4732. number of match-key arguments between zero and the number of primary
  4733. keys in the table.  Any unspecified MATCH-KEY arguments default to `#f'.
  4734. The MATCH-KEY1 ... restrict the actions of the table command to those
  4735. records whose primary keys each satisfy the corresponding MATCH-KEY
  4736. argument.  The arguments and their actions are:
  4737.     `#f'
  4738.           The false value matches any key in the corresponding position.
  4739.     an object of type procedure
  4740.           This procedure must take a single argument, the key in the
  4741.           corresponding position.  Any key for which the procedure
  4742.           returns a non-false value is a match; Any key for which the
  4743.           procedure returns a `#f' is not.
  4744.     other values
  4745.           Any other value matches only those keys `equal?' to it.
  4746.  - Function: close-table
  4747.      Subsequent operations to this table will signal an error.
  4748.  - Constant: column-names
  4749.  - Constant: column-foreigns
  4750.  - Constant: column-domains
  4751.  - Constant: column-types
  4752.      Return a list of the column names, foreign-key table names, domain
  4753.      names, or type names respectively for this table.  These 4 methods
  4754.      are different from the others in that the list is returned, rather
  4755.      than a procedure to obtain the list.
  4756.  - Constant: primary-limit
  4757.      Returns the number of primary keys fields in the relations in this
  4758.      table.
  4759. File: slib.info,  Node: Catalog Representation,  Next: Unresolved Issues,  Prev: Table Operations,  Up: Relational Database
  4760. Catalog Representation
  4761. ----------------------
  4762. Each database (in an implementation) has a "system catalog" which
  4763. describes all the user accessible tables in that database (including
  4764. itself).
  4765. The system catalog base table has the following fields.  `PRI'
  4766. indicates a primary key for that table.
  4767.      PRI table-name
  4768.          column-limit            the highest column number
  4769.          coltab-name             descriptor table name
  4770.          bastab-id               data base table identifier
  4771.          user-integrity-rule
  4772.          view-procedure          A scheme thunk which, when called,
  4773.                                  produces a handle for the view.  coltab
  4774.                                  and bastab are specified if and only if
  4775.                                  view-procedure is not.
  4776. Descriptors for base tables (not views) are tables (pointed to by
  4777. system catalog).  Descriptor (base) tables have the fields:
  4778.      PRI column-number           sequential integers from 1
  4779.          primary-key?            boolean TRUE for primary key components
  4780.          column-name
  4781.          column-integrity-rule
  4782.          domain-name
  4783. A "primary key" is any column marked as `primary-key?' in the
  4784. corresponding descriptor table.  All the `primary-key?' columns must
  4785. have lower column numbers than any non-`primary-key?' columns.  Every
  4786. table must have at least one primary key.  Primary keys must be
  4787. sufficient to distinguish all rows from each other in the table.  All of
  4788. the system defined tables have a single primary key.
  4789. This package currently supports tables having from 1 to 4 primary keys
  4790. if there are non-primary columns, and any (natural) number if *all*
  4791. columns are primary keys.  If you need more than 4 primary keys, I would
  4792. like to hear what you are doing!
  4793. A "domain" is a category describing the allowable values to occur in a
  4794. column.  It is described by a (base) table with the fields:
  4795.      PRI domain-name
  4796.          foreign-table
  4797.          domain-integrity-rule
  4798.          type-id
  4799.          type-param
  4800. The "type-id" field value is a symbol.  This symbol may be used by the
  4801. underlying base table implementation in storing that field.
  4802. If the `foreign-table' field is non-`#f' then that field names a table
  4803. from the catalog.  The values for that domain must match a primary key
  4804. of the table referenced by the TYPE-PARAM (or `#f', if allowed).  This
  4805. package currently does not support composite foreign-keys.
  4806. The types for which support is planned are:
  4807.          atom
  4808.          symbol
  4809.          string                  [<length>]
  4810.          number                  [<base>]
  4811.          money                   <currency>
  4812.          date-time
  4813.          boolean
  4814.      
  4815.          foreign-key             <table-name>
  4816.          expression
  4817.          virtual                 <expression>
  4818. File: slib.info,  Node: Unresolved Issues,  Next: Database Utilities,  Prev: Catalog Representation,  Up: Relational Database
  4819. Unresolved Issues
  4820. -----------------
  4821.   Although `rdms.scm' is not large, I found it very difficult to write
  4822. (six rewrites).  I am not aware of any other examples of a generalized
  4823. relational system (although there is little new in CS).  I left out
  4824. several aspects of the Relational model in order to simplify the job.
  4825. The major features lacking (which might be addressed portably) are
  4826. views, transaction boundaries, and protection.
  4827.   Protection needs a model for specifying priveledges.  Given how
  4828. operations are accessed from handles it should not be difficult to
  4829. restrict table accesses to those allowed for that user.
  4830.   The system catalog has a field called `view-procedure'.  This should
  4831. allow a purely functional implementation of views.  This will work but
  4832. is unsatisfying for views resulting from a "select"ion (subset of
  4833. rows); for whole table operations it will not be possible to reduce the
  4834. number of keys scanned over when the selection is specified only by an
  4835. opaque procedure.
  4836.   Transaction boundaries present the most intriguing area.  Transaction
  4837. boundaries are actually a feature of the "Comprehensive Language" of the
  4838. Relational database and not of the database.  Scheme would seem to
  4839. provide the opportunity for an extremely clean semantics for transaction
  4840. boundaries since the builtin procedures with side effects are small in
  4841. number and easily identified.
  4842.   These side-effect builtin procedures might all be portably redefined
  4843. to versions which properly handled transactions.  Compiled library
  4844. routines would need to be recompiled as well.  Many system extensions
  4845. (delete-file, system, etc.) would also need to be redefined.
  4846. There are 2 scope issues that must be resolved for multiprocess
  4847. transaction boundaries:
  4848. Process scope
  4849.      The actions captured by a transaction should be only for the
  4850.      process which invoked the start of transaction.  Although standard
  4851.      Scheme does not provide process primitives as such, `dynamic-wind'
  4852.      would provide a workable hook into process switching for many
  4853.      implementations.
  4854. Shared utilities with state
  4855.      Some shared utilities have state which should *not* be part of a
  4856.      transaction.  An example would be calling a pseudo-random number
  4857.      generator.  If the success of a transaction depended on the
  4858.      pseudo-random number and failed, the state of the generator would
  4859.      be set back.  Subsequent calls would keep returning the same
  4860.      number and keep failing.
  4861.      Pseudo-random number generators are not reentrant; thus they would
  4862.      require locks in order to operate properly in a multiprocess
  4863.      environment.  Are all examples of utilities whose state should not
  4864.      be part of transactions also non-reentrant?  If so, perhaps
  4865.      suspending transaction capture for the duration of locks would
  4866.      solve this problem.
  4867. File: slib.info,  Node: Database Utilities,  Next: Database Reports,  Prev: Unresolved Issues,  Up: Relational Database
  4868. Database Utilities
  4869. ------------------
  4870.   `(require 'database-utilities)'
  4871. This enhancement wraps a utility layer on `relational-database' which
  4872. provides:
  4873.    * Automatic loading of the appropriate base-table package when
  4874.      opening a database.
  4875.    * Automatic execution of initialization commands stored in database.
  4876.    * Transparent execution of database commands stored in `*commands*'
  4877.      table in database.
  4878. Also included are utilities which provide:
  4879.    * Data definition from Scheme lists and
  4880.    * Report generation
  4881. for any SLIB relational database.
  4882.  - Function: create-database FILENAME BASE-TABLE-TYPE
  4883.      Returns an open, nearly empty enhanced (with `*commands*' table)
  4884.      relational database (with base-table type BASE-TABLE-TYPE)
  4885.      associated with FILENAME.
  4886.  - Function: open-database FILENAME
  4887.  - Function: open-database FILENAME BASE-TABLE-TYPE
  4888.      Returns an open enchanced relational database associated with
  4889.      FILENAME.  The database will be opened with base-table type
  4890.      BASE-TABLE-TYPE) if supplied.  If BASE-TABLE-TYPE is not supplied,
  4891.      `open-database' will attempt to deduce the correct
  4892.      base-table-type.  If the database can not be opened or if it lacks
  4893.      the `*commands*' table, `#f' is returned.
  4894.  - Function: open-database! FILENAME
  4895.  - Function: open-database! FILENAME BASE-TABLE-TYPE
  4896.      Returns *mutable* open enchanced relational database ...
  4897. The table `*commands*' in an "enhanced" relational-database has the
  4898. fields (with domains):
  4899.      PRI name        symbol
  4900.          parameters  parameter-list
  4901.          procedure   expression
  4902.          documentation string
  4903.   The `parameters' field is a foreign key (domain `parameter-list') of
  4904. the `*catalog-data*' table and should have the value of a table
  4905. described by `*parameter-columns*'.  This `parameter-list' table
  4906. describes the arguments suitable for passing to the associated command.
  4907. The intent of this table is to be of a form such that different
  4908. user-interfaces (for instance, pull-down menus or plain-text queries)
  4909. can operate from the same table.  A `parameter-list' table has the
  4910. following fields:
  4911.      PRI index       uint
  4912.          name        symbol
  4913.          arity       parameter-arity
  4914.          domain      domain
  4915.          defaulter   expression
  4916.          expander    expression
  4917.          documentation string
  4918.   The `arity' field can take the values:
  4919. `single'
  4920.      Requires a single parameter of the specified domain.
  4921. `optional'
  4922.      A single parameter of the specified domain or zero parameters is
  4923.      acceptable.
  4924. `boolean'
  4925.      A single boolean parameter or zero parameters (in which case `#f'
  4926.      is substituted) is acceptable.
  4927. `nary'
  4928.      Any number of parameters of the specified domain are acceptable.
  4929.      The argument passed to the command function is always a list of the
  4930.      parameters.
  4931. `nary1'
  4932.      One or more of parameters of the specified domain are acceptable.
  4933.      The argument passed to the command function is always a list of the
  4934.      parameters.
  4935.   The `domain' field specifies the domain which a parameter or
  4936. parameters in the `index'th field must satisfy.
  4937.   The `defaulter' field is an expression whose value is either `#f' or
  4938. a procedure of one argument (the parameter-list) which returns a *list*
  4939. of the default value or values as appropriate.  Note that since the
  4940. `defaulter' procedure is called every time a default parameter is
  4941. needed for this column, "sticky" defaults can be implemented using
  4942. shared state with the domain-integrity-rule.
  4943. Invoking Commands
  4944. .................
  4945.   When an enhanced relational-database is called with a symbol which
  4946. matches a NAME in the `*commands*' table, the associated procedure
  4947. expression is evaluated and applied to the enhanced
  4948. relational-database.  A procedure should then be returned which the user
  4949. can invoke on (optional) arguments.
  4950.   The command `*initialize*' is special.  If present in the
  4951. `*commands*' table, `open-database' or `open-database!'  will return
  4952. the value of the `*initialize*' command.  Notice that arbitrary code
  4953. can be run when the `*initialize*' procedure is automatically applied
  4954. to the enhanced relational-database.
  4955.   Note also that if you wish to shadow or hide from the user
  4956. relational-database methods described in *Note Relational Database
  4957. Operations::, this can be done by a dispatch in the closure returned by
  4958. the `*initialize*' expression rather than by entries in the
  4959. `*commands*' table if it is desired that the underlying methods remain
  4960. accessible to code in the `*commands*' table.
  4961.  - Function: make-command-server RDB TABLE-NAME
  4962.      Returns a procedure of 2 arguments, a (symbol) command and a
  4963.      call-back procedure.  When this returned procedure is called, it
  4964.      looks up COMMAND in table TABLE-NAME and calls the call-back
  4965.      procedure with arguments:
  4966.     COMMAND
  4967.           The COMMAND
  4968.     COMMAND-VALUE
  4969.           The result of evaluating the expression in the PROCEDURE
  4970.           field of TABLE-NAME and calling it with RDB.
  4971.     PARAMETER-NAME
  4972.           A list of the "official" name of each parameter.  Corresponds
  4973.           to the `name' field of the COMMAND's parameter-table.
  4974.     POSITIONS
  4975.           A list of the positive integer index of each parameter.
  4976.           Corresponds to the `index' field of the COMMAND's
  4977.           parameter-table.
  4978.     ARITIES
  4979.           A list of the arities of each parameter.  Corresponds to the
  4980.           `arity' field of the COMMAND's parameter-table.  For a
  4981.           description of `arity' see table above.
  4982.     TYPES
  4983.           A list of the type name of each parameter.  Correspnds to the
  4984.           `type-id' field of the contents of the `domain' of the
  4985.           COMMAND's parameter-table.
  4986.     DEFAULTERS
  4987.           A list of the defaulters for each parameter.  Corresponds to
  4988.           the `defaulters' field of the COMMAND's parameter-table.
  4989.     DOMAIN-INTEGRITY-RULES
  4990.           A list of procedures (one for each parameter) which tests
  4991.           whether a value for a parameter is acceptable for that
  4992.           parameter.  The procedure should be called with each datum in
  4993.           the list for `nary' arity parameters.
  4994.     ALIASES
  4995.           A list of lists of `(alias parameter-name)'.  There can be
  4996.           more than one alias per PARAMETER-NAME.
  4997.   For information about parameters, *Note Parameter lists::.  Here is an
  4998. example of setting up a command with arguments and parsing those
  4999. arguments from a `getopt' style argument list (*note Getopt::.).
  5000.      (require 'database-utilities)
  5001.      (require 'fluid-let)
  5002.      (require 'parameters)
  5003.      (require 'getopt)
  5004.      
  5005.      (define my-rdb (create-database #f 'alist-table))
  5006.      
  5007.      (define-tables my-rdb
  5008.        '(foo-params
  5009.          *parameter-columns*
  5010.          *parameter-columns*
  5011.          ((1 single-string single string
  5012.              (lambda (pl) '("str")) #f "single string")
  5013.           (2 nary-symbols nary symbol
  5014.              (lambda (pl) '()) #f "zero or more symbols")
  5015.           (3 nary1-symbols nary1 symbol
  5016.              (lambda (pl) '(symb)) #f "one or more symbols")
  5017.           (4 optional-number optional uint
  5018.              (lambda (pl) '()) #f "zero or one number")
  5019.           (5 flag boolean boolean
  5020.              (lambda (pl) '(#f)) #f "a boolean flag")))
  5021.        '(foo-pnames
  5022.          ((name string))
  5023.          ((parameter-index uint))
  5024.          (("s" 1)
  5025.           ("single-string" 1)
  5026.           ("n" 2)
  5027.           ("nary-symbols" 2)
  5028.           ("N" 3)
  5029.           ("nary1-symbols" 3)
  5030.           ("o" 4)
  5031.           ("optional-number" 4)
  5032.           ("f" 5)
  5033.           ("flag" 5)))
  5034.        '(my-commands
  5035.          ((name symbol))
  5036.          ((parameters parameter-list)
  5037.           (parameter-names parameter-name-translation)
  5038.           (procedure expression)
  5039.           (documentation string))
  5040.          ((foo
  5041.            foo-params
  5042.            foo-pnames
  5043.            (lambda (rdb) (lambda args (print args)))
  5044.            "test command arguments"))))
  5045.      
  5046.      (define (dbutil:serve-command-line rdb command-table
  5047.                                         command argc argv)
  5048.        (set! argv (if (vector? argv) (vector->list argv) argv))
  5049.        ((make-command-server rdb command-table)
  5050.         command
  5051.         (lambda (comname comval options positions
  5052.                          arities types defaulters dirs aliases)
  5053.           (apply comval (getopt->arglist
  5054.                          argc argv options positions
  5055.                          arities types defaulters dirs aliases)))))
  5056.      
  5057.      (define (cmd . opts)
  5058.        (fluid-let ((*optind* 1))
  5059.          (printf "%-34s => "
  5060.                  (call-with-output-string
  5061.                   (lambda (pt) (write (cons 'cmd opts) pt))))
  5062.          (set! opts (cons "cmd" opts))
  5063.          (force-output)
  5064.          (dbutil:serve-command-line
  5065.           my-rdb 'my-commands 'foo (length opts) opts)))
  5066.      
  5067.      (cmd)                              => ("str" () (symb) () #f)
  5068.      (cmd "-f")                         => ("str" () (symb) () #t)
  5069.      (cmd "--flag")                     => ("str" () (symb) () #t)
  5070.      (cmd "-o177")                      => ("str" () (symb) (177) #f)
  5071.      (cmd "-o" "177")                   => ("str" () (symb) (177) #f)
  5072.      (cmd "--optional" "621")           => ("str" () (symb) (621) #f)
  5073.      (cmd "--optional=621")             => ("str" () (symb) (621) #f)
  5074.      (cmd "-s" "speciality")            => ("speciality" () (symb) () #f)
  5075.      (cmd "-sspeciality")               => ("speciality" () (symb) () #f)
  5076.      (cmd "--single" "serendipity")     => ("serendipity" () (symb) () #f)
  5077.      (cmd "--single=serendipity")       => ("serendipity" () (symb) () #f)
  5078.      (cmd "-n" "gravity" "piety")       => ("str" () (piety gravity) () #f)
  5079.      (cmd "-ngravity" "piety")          => ("str" () (piety gravity) () #f)
  5080.      (cmd "--nary" "chastity")          => ("str" () (chastity) () #f)
  5081.      (cmd "--nary=chastity" "")         => ("str" () ( chastity) () #f)
  5082.      (cmd "-N" "calamity")              => ("str" () (calamity) () #f)
  5083.      (cmd "-Ncalamity")                 => ("str" () (calamity) () #f)
  5084.      (cmd "--nary1" "surety")           => ("str" () (surety) () #f)
  5085.      (cmd "--nary1=surety")             => ("str" () (surety) () #f)
  5086.      (cmd "-N" "levity" "fealty")       => ("str" () (fealty levity) () #f)
  5087.      (cmd "-Nlevity" "fealty")          => ("str" () (fealty levity) () #f)
  5088.      (cmd "--nary1" "surety" "brevity") => ("str" () (brevity surety) () #f)
  5089.      (cmd "--nary1=surety" "brevity")   => ("str" () (brevity surety) () #f)
  5090.      (cmd "-?")
  5091.      -|
  5092.      Usage: cmd [OPTION ARGUMENT ...] ...
  5093.      
  5094.        -f, --flag
  5095.        -o, --optional[=]<number>
  5096.        -n, --nary[=]<symbols> ...
  5097.        -N, --nary1[=]<symbols> ...
  5098.        -s, --single[=]<string>
  5099.      
  5100.      ERROR: getopt->parameter-list "unrecognized option" "-?"
  5101.   Some commands are defined in all extended relational-databases.  The
  5102. are called just like *Note Relational Database Operations::.
  5103.  - Function: add-domain DOMAIN-ROW
  5104.      Adds DOMAIN-ROW to the "domains" table if there is no row in the
  5105.      domains table associated with key `(car DOMAIN-ROW)' and returns
  5106.      `#t'.  Otherwise returns `#f'.
  5107.      For the fields and layout of the domain table, *Note Catalog
  5108.      Representation::.  Currently, these fields are
  5109.         * domain-name
  5110.         * foreign-table
  5111.         * domain-integrity-rule
  5112.         * type-id
  5113.         * type-param
  5114.      The following example adds 3 domains to the `build' database.
  5115.      `Optstring' is either a string or `#f'.  `filename' is a string
  5116.      and `build-whats' is a symbol.
  5117.           (for-each (build 'add-domain)
  5118.                     '((optstring #f
  5119.                                  (lambda (x) (or (not x) (string? x)))
  5120.                                  string
  5121.                                  #f)
  5122.                       (filename #f #f string #f)
  5123.                       (build-whats #f #f symbol #f)))
  5124.  - Function: delete-domain DOMAIN-NAME
  5125.      Removes and returns the DOMAIN-NAME row from the "domains" table.
  5126.  - Function: domain-checker DOMAIN
  5127.      Returns a procedure to check an argument for conformance to domain
  5128.      DOMAIN.
  5129. Defining Tables
  5130. ...............
  5131.  - Procedure: define-tables RDB SPEC-0 ...
  5132.      Adds tables as specified in SPEC-0 ... to the open
  5133.      relational-database RDB.  Each SPEC has the form:
  5134.           (<name> <descriptor-name> <descriptor-name> <rows>)
  5135.      or
  5136.           (<name> <primary-key-fields> <other-fields> <rows>)
  5137.      where <name> is the table name, <descriptor-name> is the symbol
  5138.      name of a descriptor table, <primary-key-fields> and
  5139.      <other-fields> describe the primary keys and other fields
  5140.      respectively, and <rows> is a list of data rows to be added to the
  5141.      table.
  5142.      <primary-key-fields> and <other-fields> are lists of field
  5143.      descriptors of the form:
  5144.           (<column-name> <domain>)
  5145.      or
  5146.           (<column-name> <domain> <column-integrity-rule>)
  5147.      where <column-name> is the column name, <domain> is the domain of
  5148.      the column, and <column-integrity-rule> is an expression whose
  5149.      value is a procedure of one argument (which returns `#f' to signal
  5150.      an error).
  5151.      If <domain> is not a defined domain name and it matches the name of
  5152.      this table or an already defined (in one of SPEC-0 ...) single key
  5153.      field table, a foriegn-key domain will be created for it.
  5154. The following example shows a new database with the name of `foo.db'
  5155. being created with tables describing processor families and
  5156. processor/os/compiler combinations.
  5157. The database command `define-tables' is defined to call `define-tables'
  5158. with its arguments.  The database is also configured to print `Welcome'
  5159. when the database is opened.  The database is then closed and reopened.
  5160.      (require 'database-utilities)
  5161.      (define my-rdb (create-database "foo.db" 'alist-table))
  5162.      
  5163.      (define-tables my-rdb
  5164.        '(*commands*
  5165.          ((name symbol))
  5166.          ((parameters parameter-list)
  5167.           (procedure expression)
  5168.           (documentation string))
  5169.          ((define-tables
  5170.            no-parameters
  5171.            no-parameter-names
  5172.            (lambda (rdb) (lambda specs (apply define-tables rdb specs)))
  5173.            "Create or Augment tables from list of specs")
  5174.           (*initialize*
  5175.            no-parameters
  5176.            no-parameter-names
  5177.            (lambda (rdb) (display "Welcome") (newline) rdb)
  5178.            "Print Welcome"))))
  5179.      
  5180.      ((my-rdb 'define-tables)
  5181.       '(processor-family
  5182.         ((family    atom))
  5183.         ((also-ran  processor-family))
  5184.         ((m68000           #f)
  5185.          (m68030           m68000)
  5186.          (i386             8086)
  5187.          (8086             #f)
  5188.          (powerpc          #f)))
  5189.      
  5190.       '(platform
  5191.         ((name      symbol))
  5192.         ((processor processor-family)
  5193.          (os        symbol)
  5194.          (compiler  symbol))
  5195.         ((aix              powerpc aix     -)
  5196.          (amiga-dice-c     m68000  amiga   dice-c)
  5197.          (amiga-aztec      m68000  amiga   aztec)
  5198.          (amiga-sas/c-5.10 m68000  amiga   sas/c)
  5199.          (atari-st-gcc     m68000  atari   gcc)
  5200.          (atari-st-turbo-c m68000  atari   turbo-c)
  5201.          (borland-c-3.1    8086    ms-dos  borland-c)
  5202.          (djgpp            i386    ms-dos  gcc)
  5203.          (linux            i386    linux   gcc)
  5204.          (microsoft-c      8086    ms-dos  microsoft-c)
  5205.          (os/2-emx         i386    os/2    gcc)
  5206.          (turbo-c-2        8086    ms-dos  turbo-c)
  5207.          (watcom-9.0       i386    ms-dos  watcom))))
  5208.      
  5209.      ((my-rdb 'close-database))
  5210.      
  5211.      (set! my-rdb (open-database "foo.db" 'alist-table))
  5212.      -|
  5213.      Welcome
  5214. File: slib.info,  Node: Database Reports,  Next: Database Browser,  Prev: Database Utilities,  Up: Relational Database
  5215. Database Reports
  5216. ----------------
  5217. Code for generating database reports is in `report.scm'.  After writing
  5218. it using `format', I discovered that Common-Lisp `format' is not
  5219. useable for this application because there is no mechanismm for
  5220. truncating fields.  `report.scm' needs to be rewritten using `printf'.
  5221.  - Procedure: create-report RDB DESTINATION REPORT-NAME TABLE
  5222.  - Procedure: create-report RDB DESTINATION REPORT-NAME
  5223.      The symbol REPORT-NAME must be primary key in the table named
  5224.      `*reports*' in the relational database RDB.  DESTINATION is a
  5225.      port, string, or symbol.  If DESTINATION is a:
  5226.     port
  5227.           The table is created as ascii text and written to that port.
  5228.     string
  5229.           The table is created as ascii text and written to the file
  5230.           named by DESTINATION.
  5231.     symbol
  5232.           DESTINATION is the primary key for a row in the table named
  5233.           *printers*.
  5234.      The report is prepared as follows:                                       |
  5235.                                                                               |
  5236.         * `Format' (*note Format::.) is called with the `header' field        |
  5237.           and the (list of) `column-names' of the table.                      |
  5238.                                                                               |
  5239.         * `Format' is called with the `reporter' field and (on                |
  5240.           successive calls) each record in the natural order for the          |
  5241.           table.  A count is kept of the number of newlines output by         |
  5242.           format.  When the number of newlines to be output exceeds the       |
  5243.           number of lines per page, the set of lines will be broken if        |
  5244.           there are more than `minimum-break' left on this page and the       |
  5245.           number of lines for this row is larger or equal to twice            |
  5246.           `minimum-break'.                                                    |
  5247.                                                                               |
  5248.         * `Format' is called with the `footer' field and the (list of)        |
  5249.           `column-names' of the table.  The footer field should not           |
  5250.           output a newline.                                                   |
  5251.                                                                               |
  5252.         * A new page is output.                                               |
  5253.                                                                               |
  5254.         * This entire process repeats until all the rows are output.          |
  5255.                                                                               |
  5256.   Each row in the table *reports* has the fields:
  5257.      The report name.
  5258. default-table
  5259.      The table to report on if none is specified.
  5260. header, footer
  5261.      A `format' string.  At the beginning and end of each page
  5262.      respectively, `format' is called with this string and the (list of)      |
  5263.      column-names of this table.                                              |
  5264. reporter
  5265.      A `format' string.  For each row in the table, `format' is called        |
  5266.      with this string and the row.                                            |
  5267. minimum-break
  5268.      The minimum number of lines into which the report lines for a row        |
  5269.      can be broken.  Use `0' if a row's lines should not be broken over       |
  5270.      page boundaries.                                                         |
  5271.   Each row in the table *printers* has the fields:
  5272.      The printer name.
  5273. print-procedure
  5274.      The procedure to call to actually print.
  5275.                                                                               |
  5276. File: slib.info,  Node: Database Browser,  Prev: Database Reports,  Up: Relational Database
  5277. Database Browser
  5278. ----------------
  5279.   (require 'database-browse)
  5280.  - Procedure: browse DATABASE
  5281.      Prints the names of all the tables in DATABASE and sets browse's
  5282.      default to DATABASE.
  5283.  - Procedure: browse
  5284.      Prints the names of all the tables in the default database.
  5285.  - Procedure: browse TABLE-NAME
  5286.      For each record of the table named by the symbol TABLE-NAME,
  5287.      prints a line composed of all the field values.
  5288.  - Procedure: browse PATHNAME
  5289.      Opens the database named by the string PATHNAME, prints the names
  5290.      of all its tables, and sets browse's default to the database.
  5291.  - Procedure: browse DATABASE TABLE-NAME
  5292.      Sets browse's default to DATABASE and prints the records of the
  5293.      table named by the symbol TABLE-NAME.
  5294.  - Procedure: browse PATHNAME TABLE-NAME
  5295.      Opens the database named by the string PATHNAME and sets browse's
  5296.      default to it; `browse' prints the records of the table named by
  5297.      the symbol TABLE-NAME.
  5298. File: slib.info,  Node: Weight-Balanced Trees,  Prev: Relational Database,  Up: Database Packages
  5299. Weight-Balanced Trees
  5300. =====================
  5301.   `(require 'wt-tree)'
  5302.   Balanced binary trees are a useful data structure for maintaining
  5303. large sets of ordered objects or sets of associations whose keys are
  5304. ordered.  MIT Scheme has an comprehensive implementation of
  5305. weight-balanced binary trees which has several advantages over the
  5306. other data structures for large aggregates:
  5307.    * In addition to the usual element-level operations like insertion,
  5308.      deletion and lookup, there is a full complement of collection-level
  5309.      operations, like set intersection, set union and subset test, all
  5310.      of which are implemented with good orders of growth in time and
  5311.      space.  This makes weight balanced trees ideal for rapid
  5312.      prototyping of functionally derived specifications.
  5313.    * An element in a tree may be indexed by its position under the
  5314.      ordering of the keys, and the ordinal position of an element may
  5315.      be determined, both with reasonable efficiency.
  5316.    * Operations to find and remove minimum element make weight balanced
  5317.      trees simple to use for priority queues.
  5318.    * The implementation is *functional* rather than *imperative*.  This
  5319.      means that operations like `inserting' an association in a tree do
  5320.      not destroy the old tree, in much the same way that `(+ 1 x)'
  5321.      modifies neither the constant 1 nor the value bound to `x'.  The
  5322.      trees are referentially transparent thus the programmer need not
  5323.      worry about copying the trees.  Referential transparency allows
  5324.      space efficiency to be achieved by sharing subtrees.
  5325.   These features make weight-balanced trees suitable for a wide range of
  5326. applications, especially those that require large numbers of sets or
  5327. discrete maps.  Applications that have a few global databases and/or
  5328. concentrate on element-level operations like insertion and lookup are
  5329. probably better off using hash-tables or red-black trees.
  5330.   The *size* of a tree is the number of associations that it contains.
  5331. Weight balanced binary trees are balanced to keep the sizes of the
  5332. subtrees of each node within a constant factor of each other.  This
  5333. ensures logarithmic times for single-path operations (like lookup and
  5334. insertion).  A weight balanced tree takes space that is proportional to
  5335. the number of associations in the tree.  For the current
  5336. implementation, the constant of proportionality is six words per
  5337. association.
  5338.   Weight balanced trees can be used as an implementation for either
  5339. discrete sets or discrete maps (associations).  Sets are implemented by
  5340. ignoring the datum that is associated with the key.  Under this scheme
  5341. if an associations exists in the tree this indicates that the key of the
  5342. association is a member of the set.  Typically a value such as `()',
  5343. `#t' or `#f' is associated with the key.
  5344.   Many operations can be viewed as computing a result that, depending on
  5345. whether the tree arguments are thought of as sets or maps, is known by
  5346. two different names.  An example is `wt-tree/member?', which, when
  5347. regarding the tree argument as a set, computes the set membership
  5348. operation, but, when regarding the tree as a discrete map,
  5349. `wt-tree/member?' is the predicate testing if the map is defined at an
  5350. element in its domain.  Most names in this package have been chosen
  5351. based on interpreting the trees as sets, hence the name
  5352. `wt-tree/member?' rather than `wt-tree/defined-at?'.
  5353.   The weight balanced tree implementation is a run-time-loadable option.
  5354. To use weight balanced trees, execute
  5355.      (load-option 'wt-tree)
  5356. once before calling any of the procedures defined here.
  5357. * Menu:
  5358. * Construction of Weight-Balanced Trees::
  5359. * Basic Operations on Weight-Balanced Trees::
  5360. * Advanced Operations on Weight-Balanced Trees::
  5361. * Indexing Operations on Weight-Balanced Trees::
  5362. File: slib.info,  Node: Construction of Weight-Balanced Trees,  Next: Basic Operations on Weight-Balanced Trees,  Prev: Weight-Balanced Trees,  Up: Weight-Balanced Trees
  5363. Construction of Weight-Balanced Trees
  5364. -------------------------------------
  5365.   Binary trees require there to be a total order on the keys used to
  5366. arrange the elements in the tree.  Weight balanced trees are organized
  5367. by *types*, where the type is an object encapsulating the ordering
  5368. relation.  Creating a tree is a two-stage process.  First a tree type
  5369. must be created from the predicate which gives the ordering.  The tree
  5370. type is then used for making trees, either empty or singleton trees or
  5371. trees from other aggregate structures like association lists.  Once
  5372. created, a tree `knows' its type and the type is used to test
  5373. compatibility between trees in operations taking two trees.  Usually a
  5374. small number of tree types are created at the beginning of a program and
  5375. used many times throughout the program's execution.
  5376.  - procedure+: make-wt-tree-type KEY<?
  5377.      This procedure creates and returns a new tree type based on the
  5378.      ordering predicate KEY<?.  KEY<? must be a total ordering, having
  5379.      the property that for all key values `a', `b' and `c':
  5380.           (key<? a a)                         => #f
  5381.           (and (key<? a b) (key<? b a))       => #f
  5382.           (if (and (key<? a b) (key<? b c))
  5383.               (key<? a c)
  5384.               #t)                             => #t
  5385.      Two key values are assumed to be equal if neither is less than the
  5386.      other by KEY<?.
  5387.      Each call to `make-wt-tree-type' returns a distinct value, and
  5388.      trees are only compatible if their tree types are `eq?'.  A
  5389.      consequence is that trees that are intended to be used in binary
  5390.      tree operations must all be created with a tree type originating
  5391.      from the same call to `make-wt-tree-type'.
  5392.  - variable+: number-wt-type
  5393.      A standard tree type for trees with numeric keys.  `Number-wt-type'
  5394.      could have been defined by
  5395.           (define number-wt-type (make-wt-tree-type  <))
  5396.  - variable+: string-wt-type
  5397.      A standard tree type for trees with string keys.  `String-wt-type'
  5398.      could have been defined by
  5399.           (define string-wt-type (make-wt-tree-type  string<?))
  5400.  - procedure+: make-wt-tree WT-TREE-TYPE
  5401.      This procedure creates and returns a newly allocated weight
  5402.      balanced tree.  The tree is empty, i.e. it contains no
  5403.      associations.  WT-TREE-TYPE is a weight balanced tree type
  5404.      obtained by calling `make-wt-tree-type'; the returned tree has
  5405.      this type.
  5406.  - procedure+: singleton-wt-tree WT-TREE-TYPE KEY DATUM
  5407.      This procedure creates and returns a newly allocated weight
  5408.      balanced tree.  The tree contains a single association, that of
  5409.      DATUM with KEY.  WT-TREE-TYPE is a weight balanced tree type
  5410.      obtained by calling `make-wt-tree-type'; the returned tree has
  5411.      this type.
  5412.  - procedure+: alist->wt-tree TREE-TYPE ALIST
  5413.      Returns a newly allocated weight-balanced tree that contains the
  5414.      same associations as ALIST.  This procedure is equivalent to:
  5415.           (lambda (type alist)
  5416.             (let ((tree (make-wt-tree type)))
  5417.               (for-each (lambda (association)
  5418.                           (wt-tree/add! tree
  5419.                                         (car association)
  5420.                                         (cdr association)))
  5421.                         alist)
  5422.               tree))
  5423. File: slib.info,  Node: Basic Operations on Weight-Balanced Trees,  Next: Advanced Operations on Weight-Balanced Trees,  Prev: Construction of Weight-Balanced Trees,  Up: Weight-Balanced Trees
  5424. Basic Operations on Weight-Balanced Trees
  5425. -----------------------------------------
  5426.   This section describes the basic tree operations on weight balanced
  5427. trees.  These operations are the usual tree operations for insertion,
  5428. deletion and lookup, some predicates and a procedure for determining the
  5429. number of associations in a tree.
  5430.  - procedure+: wt-tree? OBJECT
  5431.      Returns `#t' if OBJECT is a weight-balanced tree, otherwise
  5432.      returns `#f'.
  5433.  - procedure+: wt-tree/empty? WT-TREE
  5434.      Returns `#t' if WT-TREE contains no associations, otherwise
  5435.      returns `#f'.
  5436.  - procedure+: wt-tree/size WT-TREE
  5437.      Returns the number of associations in WT-TREE, an exact
  5438.      non-negative integer.  This operation takes constant time.
  5439.  - procedure+: wt-tree/add WT-TREE KEY DATUM
  5440.      Returns a new tree containing all the associations in WT-TREE and
  5441.      the association of DATUM with KEY.  If WT-TREE already had an
  5442.      association for KEY, the new association overrides the old.  The
  5443.      average and worst-case times required by this operation are
  5444.      proportional to the logarithm of the number of associations in
  5445.      WT-TREE.
  5446.  - procedure+: wt-tree/add! WT-TREE KEY DATUM
  5447.      Associates DATUM with KEY in WT-TREE and returns an unspecified
  5448.      value.  If WT-TREE already has an association for KEY, that
  5449.      association is replaced.  The average and worst-case times
  5450.      required by this operation are proportional to the logarithm of
  5451.      the number of associations in WT-TREE.
  5452.  - procedure+: wt-tree/member? KEY WT-TREE
  5453.      Returns `#t' if WT-TREE contains an association for KEY, otherwise
  5454.      returns `#f'.  The average and worst-case times required by this
  5455.      operation are proportional to the logarithm of the number of
  5456.      associations in WT-TREE.
  5457.  - procedure+: wt-tree/lookup WT-TREE KEY DEFAULT
  5458.      Returns the datum associated with KEY in WT-TREE.  If WT-TREE
  5459.      doesn't contain an association for KEY, DEFAULT is returned.  The
  5460.      average and worst-case times required by this operation are
  5461.      proportional to the logarithm of the number of associations in
  5462.      WT-TREE.
  5463.  - procedure+: wt-tree/delete WT-TREE KEY
  5464.      Returns a new tree containing all the associations in WT-TREE,
  5465.      except that if WT-TREE contains an association for KEY, it is
  5466.      removed from the result.  The average and worst-case times required
  5467.      by this operation are proportional to the logarithm of the number
  5468.      of associations in WT-TREE.
  5469.  - procedure+: wt-tree/delete! WT-TREE KEY
  5470.      If WT-TREE contains an association for KEY the association is
  5471.      removed.  Returns an unspecified value.  The average and worst-case
  5472.      times required by this operation are proportional to the logarithm
  5473.      of the number of associations in WT-TREE.
  5474. File: slib.info,  Node: Advanced Operations on Weight-Balanced Trees,  Next: Indexing Operations on Weight-Balanced Trees,  Prev: Basic Operations on Weight-Balanced Trees,  Up: Weight-Balanced Trees
  5475. Advanced Operations on Weight-Balanced Trees
  5476. --------------------------------------------
  5477.   In the following the *size* of a tree is the number of associations
  5478. that the tree contains, and a *smaller* tree contains fewer
  5479. associations.
  5480.  - procedure+: wt-tree/split< WT-TREE BOUND
  5481.      Returns a new tree containing all and only the associations in
  5482.      WT-TREE which have a key that is less than BOUND in the ordering
  5483.      relation of the tree type of WT-TREE.  The average and worst-case
  5484.      times required by this operation are proportional to the logarithm
  5485.      of the size of WT-TREE.
  5486.  - procedure+: wt-tree/split> WT-TREE BOUND
  5487.      Returns a new tree containing all and only the associations in
  5488.      WT-TREE which have a key that is greater than BOUND in the
  5489.      ordering relation of the tree type of WT-TREE.  The average and
  5490.      worst-case times required by this operation are proportional to the
  5491.      logarithm of size of WT-TREE.
  5492.  - procedure+: wt-tree/union WT-TREE-1 WT-TREE-2
  5493.      Returns a new tree containing all the associations from both trees.
  5494.      This operation is asymmetric: when both trees have an association
  5495.      for the same key, the returned tree associates the datum from
  5496.      WT-TREE-2 with the key.  Thus if the trees are viewed as discrete
  5497.      maps then `wt-tree/union' computes the map override of WT-TREE-1 by
  5498.      WT-TREE-2.  If the trees are viewed as sets the result is the set
  5499.      union of the arguments.  The worst-case time required by this
  5500.      operation is proportional to the sum of the sizes of both trees.
  5501.      If the minimum key of one tree is greater than the maximum key of
  5502.      the other tree then the time required is at worst proportional to
  5503.      the logarithm of the size of the larger tree.
  5504.  - procedure+: wt-tree/intersection WT-TREE-1 WT-TREE-2
  5505.      Returns a new tree containing all and only those associations from
  5506.      WT-TREE-1 which have keys appearing as the key of an association
  5507.      in WT-TREE-2.  Thus the associated data in the result are those
  5508.      from WT-TREE-1.  If the trees are being used as sets the result is
  5509.      the set intersection of the arguments.  As a discrete map
  5510.      operation, `wt-tree/intersection' computes the domain restriction
  5511.      of WT-TREE-1 to (the domain of) WT-TREE-2.  The time required by
  5512.      this operation is never worse that proportional to the sum of the
  5513.      sizes of the trees.
  5514.  - procedure+: wt-tree/difference WT-TREE-1 WT-TREE-2
  5515.      Returns a new tree containing all and only those associations from
  5516.      WT-TREE-1 which have keys that *do not* appear as the key of an
  5517.      association in WT-TREE-2.  If the trees are viewed as sets the
  5518.      result is the asymmetric set difference of the arguments.  As a
  5519.      discrete map operation, it computes the domain restriction of
  5520.      WT-TREE-1 to the complement of (the domain of) WT-TREE-2.  The
  5521.      time required by this operation is never worse that proportional to
  5522.      the sum of the sizes of the trees.
  5523.  - procedure+: wt-tree/subset? WT-TREE-1 WT-TREE-2
  5524.      Returns `#t' iff the key of each association in WT-TREE-1 is the
  5525.      key of some association in WT-TREE-2, otherwise returns `#f'.
  5526.      Viewed as a set operation, `wt-tree/subset?' is the improper subset
  5527.      predicate.  A proper subset predicate can be constructed:
  5528.           (define (proper-subset? s1 s2)
  5529.             (and (wt-tree/subset? s1 s2)
  5530.                  (< (wt-tree/size s1) (wt-tree/size s2))))
  5531.      As a discrete map operation, `wt-tree/subset?' is the subset test
  5532.      on the domain(s) of the map(s).  In the worst-case the time
  5533.      required by this operation is proportional to the size of
  5534.      WT-TREE-1.
  5535.  - procedure+: wt-tree/set-equal? WT-TREE-1 WT-TREE-2
  5536.      Returns `#t' iff for every association in WT-TREE-1 there is an
  5537.      association in WT-TREE-2 that has the same key, and *vice versa*.
  5538.      Viewing the arguments as sets `wt-tree/set-equal?' is the set
  5539.      equality predicate.  As a map operation it determines if two maps
  5540.      are defined on the same domain.
  5541.      This procedure is equivalent to
  5542.           (lambda (wt-tree-1 wt-tree-2)
  5543.             (and (wt-tree/subset? wt-tree-1 wt-tree-2
  5544.                  (wt-tree/subset? wt-tree-2 wt-tree-1)))
  5545.      In the worst-case the time required by this operation is
  5546.      proportional to the size of the smaller tree.
  5547.  - procedure+: wt-tree/fold COMBINER INITIAL WT-TREE
  5548.      This procedure reduces WT-TREE by combining all the associations,
  5549.      using an reverse in-order traversal, so the associations are
  5550.      visited in reverse order.  COMBINER is a procedure of three
  5551.      arguments: a key, a datum and the accumulated result so far.
  5552.      Provided COMBINER takes time bounded by a constant, `wt-tree/fold'
  5553.      takes time proportional to the size of WT-TREE.
  5554.      A sorted association list can be derived simply:
  5555.           (wt-tree/fold  (lambda (key datum list)
  5556.                            (cons (cons key datum) list))
  5557.                          '()
  5558.                          WT-TREE))
  5559.      The data in the associations can be summed like this:
  5560.           (wt-tree/fold  (lambda (key datum sum) (+ sum datum))
  5561.                          0
  5562.                          WT-TREE)
  5563.  - procedure+: wt-tree/for-each ACTION WT-TREE
  5564.      This procedure traverses the tree in-order, applying ACTION to
  5565.      each association.  The associations are processed in increasing
  5566.      order of their keys.  ACTION is a procedure of two arguments which
  5567.      take the key and datum respectively of the association.  Provided
  5568.      ACTION takes time bounded by a constant, `wt-tree/for-each' takes
  5569.      time proportional to in the size of WT-TREE.  The example prints
  5570.      the tree:
  5571.           (wt-tree/for-each (lambda (key value)
  5572.                               (display (list key value)))
  5573.                             WT-TREE))
  5574. File: slib.info,  Node: Indexing Operations on Weight-Balanced Trees,  Prev: Advanced Operations on Weight-Balanced Trees,  Up: Weight-Balanced Trees
  5575. Indexing Operations on Weight-Balanced Trees
  5576. --------------------------------------------
  5577.   Weight balanced trees support operations that view the tree as sorted
  5578. sequence of associations.  Elements of the sequence can be accessed by
  5579. position, and the position of an element in the sequence can be
  5580. determined, both in logarthmic time.
  5581.  - procedure+: wt-tree/index WT-TREE INDEX
  5582.  - procedure+: wt-tree/index-datum WT-TREE INDEX
  5583.  - procedure+: wt-tree/index-pair WT-TREE INDEX
  5584.      Returns the 0-based INDEXth association of WT-TREE in the sorted
  5585.      sequence under the tree's ordering relation on the keys.
  5586.      `wt-tree/index' returns the INDEXth key, `wt-tree/index-datum'
  5587.      returns the datum associated with the INDEXth key and
  5588.      `wt-tree/index-pair' returns a new pair `(KEY . DATUM)' which is
  5589.      the `cons' of the INDEXth key and its datum.  The average and
  5590.      worst-case times required by this operation are proportional to
  5591.      the logarithm of the number of associations in the tree.
  5592.      These operations signal an error if the tree is empty, if
  5593.      INDEX`<0', or if INDEX is greater than or equal to the number of
  5594.      associations in the tree.
  5595.      Indexing can be used to find the median and maximum keys in the
  5596.      tree as follows:
  5597.           median:   (wt-tree/index WT-TREE
  5598.                                    (quotient (wt-tree/size WT-TREE) 2))
  5599.           
  5600.           maximum:  (wt-tree/index WT-TREE
  5601.                                    (-1+ (wt-tree/size WT-TREE)))
  5602.  - procedure+: wt-tree/rank WT-TREE KEY
  5603.      Determines the 0-based position of KEY in the sorted sequence of
  5604.      the keys under the tree's ordering relation, or `#f' if the tree
  5605.      has no association with for KEY.  This procedure returns either an
  5606.      exact non-negative integer or `#f'.  The average and worst-case
  5607.      times required by this operation are proportional to the logarithm
  5608.      of the number of associations in the tree.
  5609.  - procedure+: wt-tree/min WT-TREE
  5610.  - procedure+: wt-tree/min-datum WT-TREE
  5611.  - procedure+: wt-tree/min-pair WT-TREE
  5612.      Returns the association of WT-TREE that has the least key under
  5613.      the tree's ordering relation.  `wt-tree/min' returns the least key,
  5614.      `wt-tree/min-datum' returns the datum associated with the least key
  5615.      and `wt-tree/min-pair' returns a new pair `(key . datum)' which is
  5616.      the `cons' of the minimum key and its datum.  The average and
  5617.      worst-case times required by this operation are proportional to the
  5618.      logarithm of the number of associations in the tree.
  5619.      These operations signal an error if the tree is empty.  They could
  5620.      be written
  5621.           (define (wt-tree/min tree)        (wt-tree/index tree 0))
  5622.           (define (wt-tree/min-datum tree)  (wt-tree/index-datum tree 0))
  5623.           (define (wt-tree/min-pair tree)   (wt-tree/index-pair tree 0))
  5624.  - procedure+: wt-tree/delete-min WT-TREE
  5625.      Returns a new tree containing all of the associations in WT-TREE
  5626.      except the association with the least key under the WT-TREE's
  5627.      ordering relation.  An error is signalled if the tree is empty.
  5628.      The average and worst-case times required by this operation are
  5629.      proportional to the logarithm of the number of associations in the
  5630.      tree.  This operation is equivalent to
  5631.           (wt-tree/delete WT-TREE (wt-tree/min WT-TREE))
  5632.  - procedure+: wt-tree/delete-min! WT-TREE
  5633.      Removes the association with the least key under the WT-TREE's
  5634.      ordering relation.  An error is signalled if the tree is empty.
  5635.      The average and worst-case times required by this operation are
  5636.      proportional to the logarithm of the number of associations in the
  5637.      tree.  This operation is equivalent to
  5638.           (wt-tree/delete! WT-TREE (wt-tree/min WT-TREE))
  5639. File: slib.info,  Node: Other Packages,  Next: About SLIB,  Prev: Database Packages,  Up: Top
  5640. Other Packages
  5641. **************
  5642. * Menu:
  5643. * Data Structures::             Various data structures.
  5644. * Procedures::                  Miscellaneous utility procedures.
  5645. * Standards Support::           Support for Scheme Standards.
  5646. * Session Support::             REPL and Debugging.
  5647. * Extra-SLIB Packages::
  5648. File: slib.info,  Node: Data Structures,  Next: Procedures,  Prev: Other Packages,  Up: Other Packages
  5649. Data Structures
  5650. ===============
  5651. * Menu:
  5652. * Arrays::                      'array
  5653. * Array Mapping::               'array-for-each
  5654. * Association Lists::           'alist
  5655. * Byte::                        'byte
  5656. * Collections::                 'collect
  5657. * Dynamic Data Type::           'dynamic
  5658. * Hash Tables::                 'hash-table
  5659. * Hashing::                     'hash, 'sierpinski, 'soundex
  5660. * Object::                      'object                                       |
  5661. * Priority Queues::             'priority-queue
  5662. * Queues::                      'queue
  5663. * Records::                     'record
  5664. * Structures::                  'struct, 'structure
  5665. File: slib.info,  Node: Arrays,  Next: Array Mapping,  Prev: Data Structures,  Up: Data Structures
  5666. Arrays
  5667. ------
  5668.   `(require 'array)'
  5669.  - Function: array? OBJ
  5670.      Returns `#t' if the OBJ is an array, and `#f' if not.
  5671.  - Function: make-array INITIAL-VALUE BOUND1 BOUND2 ...
  5672.      Creates and returns an array that has as many dimensins as there
  5673.      are BOUNDs and fills it with INITIAL-VALUE.
  5674.   When constructing an array, BOUND is either an inclusive range of
  5675. indices expressed as a two element list, or an upper bound expressed as
  5676. a single integer.  So
  5677.      (make-array 'foo 3 3) == (make-array 'foo '(0 2) '(0 2))
  5678.  - Function: make-shared-array ARRAY MAPPER BOUND1 BOUND2 ...
  5679.      `make-shared-array' can be used to create shared subarrays of other
  5680.      arrays.  The MAPPER is a function that translates coordinates in
  5681.      the new array into coordinates in the old array.  A MAPPER must be
  5682.      linear, and its range must stay within the bounds of the old
  5683.      array, but it can be otherwise arbitrary.  A simple example:
  5684.           (define fred (make-array #f 8 8))
  5685.           (define freds-diagonal
  5686.             (make-shared-array fred (lambda (i) (list i i)) 8))
  5687.           (array-set! freds-diagonal 'foo 3)
  5688.           (array-ref fred 3 3)
  5689.              => FOO
  5690.           (define freds-center
  5691.             (make-shared-array fred (lambda (i j) (list (+ 3 i) (+ 3 j)))
  5692.                                2 2))
  5693.           (array-ref freds-center 0 0)
  5694.              => FOO
  5695.  - Function: array-rank OBJ
  5696.      Returns the number of dimensions of OBJ.  If OBJ is not an array,
  5697.      0 is returned.
  5698.  - Function: array-shape ARRAY
  5699.      `array-shape' returns a list of inclusive bounds.  So:
  5700.           (array-shape (make-array 'foo 3 5))
  5701.              => ((0 2) (0 4))
  5702.  - Function: array-dimensions ARRAY
  5703.      `array-dimensions' is similar to `array-shape' but replaces
  5704.      elements with a 0 minimum with one greater than the maximum. So:
  5705.           (array-dimensions (make-array 'foo 3 5))
  5706.              => (3 5)
  5707.  - Procedure: array-in-bounds? ARRAY INDEX1 INDEX2 ...
  5708.      Returns `#t' if its arguments would be acceptable to `array-ref'.
  5709.  - Function: array-ref ARRAY INDEX1 INDEX2 ...
  5710.      Returns the element at the `(INDEX1, INDEX2)' element in ARRAY.
  5711.  - Procedure: array-set! ARRAY NEW-VALUE INDEX1 INDEX2 ...
  5712.  - Function: array-1d-ref ARRAY INDEX
  5713.  - Function: array-2d-ref ARRAY INDEX1 INDEX2
  5714.  - Function: array-3d-ref ARRAY INDEX1 INDEX2 INDEX3
  5715.  - Procedure: array-1d-set! ARRAY NEW-VALUE INDEX
  5716.  - Procedure: array-2d-set! ARRAY NEW-VALUE INDEX1 INDEX2
  5717.  - Procedure: array-3d-set! ARRAY NEW-VALUE INDEX1 INDEX2 INDEX3
  5718.   The functions are just fast versions of `array-ref' and `array-set!'
  5719. that take a fixed number of arguments, and perform no bounds checking.
  5720.   If you comment out the bounds checking code, this is about as
  5721. efficient as you could ask for without help from the compiler.
  5722.   An exercise left to the reader: implement the rest of APL.
  5723. File: slib.info,  Node: Array Mapping,  Next: Association Lists,  Prev: Arrays,  Up: Data Structures
  5724. Array Mapping
  5725. -------------
  5726.   `(require 'array-for-each)'
  5727.  - Function: array-map! ARRAY0 PROC ARRAY1 ...
  5728.      ARRAY1, ... must have the same number of dimensions as ARRAY0 and
  5729.      have a range for each index which includes the range for the
  5730.      corresponding index in ARRAY0.  PROC is applied to each tuple of
  5731.      elements of ARRAY1 ... and the result is stored as the
  5732.      corresponding element in ARRAY0.  The value returned is
  5733.      unspecified.  The order of application is unspecified.
  5734.  - Function: array-for-each PROC ARRAY0 ...
  5735.      PROC is applied to each tuple of elements of ARRAY0 ...  in
  5736.      row-major order.  The value returned is unspecified.
  5737.  - Function: array-indexes ARRAY
  5738.      Returns an array of lists of indexes for ARRAY such that, if LI is
  5739.      a list of indexes for which ARRAY is defined, (equal?  LI (apply
  5740.      array-ref (array-indexes ARRAY) LI)).
  5741.  - Function: array-index-map! ARRAY PROC
  5742.      applies PROC to the indices of each element of ARRAY in turn,
  5743.      storing the result in the corresponding element.  The value
  5744.      returned and the order of application are unspecified.
  5745.      One can implement ARRAY-INDEXES as
  5746.           (define (array-indexes array)
  5747.               (let ((ra (apply make-array #f (array-shape array))))
  5748.                 (array-index-map! ra (lambda x x))
  5749.                 ra))
  5750.      Another example:
  5751.           (define (apl:index-generator n)
  5752.               (let ((v (make-uniform-vector n 1)))
  5753.                 (array-index-map! v (lambda (i) i))
  5754.                 v))
  5755.  - Function: array-copy! SOURCE DESTINATION
  5756.      Copies every element from vector or array SOURCE to the
  5757.      corresponding element of DESTINATION.  DESTINATION must have the
  5758.      same rank as SOURCE, and be at least as large in each dimension.
  5759.      The order of copying is unspecified.
  5760. File: slib.info,  Node: Association Lists,  Next: Byte,  Prev: Array Mapping,  Up: Data Structures
  5761. Association Lists
  5762. -----------------
  5763.   `(require 'alist)'
  5764.   Alist functions provide utilities for treating a list of key-value
  5765. pairs as an associative database.  These functions take an equality
  5766. predicate, PRED, as an argument.  This predicate should be repeatable,
  5767. symmetric, and transitive.
  5768.   Alist functions can be used with a secondary index method such as hash
  5769. tables for improved performance.
  5770.  - Function: predicate->asso PRED
  5771.      Returns an "association function" (like `assq', `assv', or
  5772.      `assoc') corresponding to PRED.  The returned function returns a
  5773.      key-value pair whose key is `pred'-equal to its first argument or
  5774.      `#f' if no key in the alist is PRED-equal to the first argument.
  5775.  - Function: alist-inquirer PRED
  5776.      Returns a procedure of 2 arguments, ALIST and KEY, which returns
  5777.      the value associated with KEY in ALIST or `#f' if KEY does not
  5778.      appear in ALIST.
  5779.  - Function: alist-associator PRED
  5780.      Returns a procedure of 3 arguments, ALIST, KEY, and VALUE, which
  5781.      returns an alist with KEY and VALUE associated.  Any previous
  5782.      value associated with KEY will be lost.  This returned procedure
  5783.      may or may not have side effects on its ALIST argument.  An
  5784.      example of correct usage is:
  5785.           (define put (alist-associator string-ci=?))
  5786.           (define alist '())
  5787.           (set! alist (put alist "Foo" 9))
  5788.  - Function: alist-remover PRED
  5789.      Returns a procedure of 2 arguments, ALIST and KEY, which returns
  5790.      an alist with an association whose KEY is key removed.  This
  5791.      returned procedure may or may not have side effects on its ALIST
  5792.      argument.  An example of correct usage is:
  5793.           (define rem (alist-remover string-ci=?))
  5794.           (set! alist (rem alist "foo"))
  5795.  - Function: alist-map PROC ALIST
  5796.      Returns a new association list formed by mapping PROC over the
  5797.      keys and values of ALIST.   PROC must be a function of 2 arguments
  5798.      which returns the new value part.
  5799.  - Function: alist-for-each PROC ALIST
  5800.      Applies PROC to each pair of keys and values of ALIST.  PROC must
  5801.      be a function of 2 arguments.  The returned value is unspecified.
  5802. File: slib.info,  Node: Byte,  Next: Collections,  Prev: Association Lists,  Up: Data Structures
  5803.   `(require 'byte)'
  5804.   Some algorithms are expressed in terms of arrays of small integers.
  5805. Using Scheme strings to implement these arrays is not portable vis-a-vis
  5806. the correspondence between integers and characters and non-ascii
  5807. character sets.  These functions abstract the notion of a "byte".
  5808.  - Function: byte-ref BYTES K
  5809.      K must be a valid index of BYTES.  `byte-ref' returns byte K of
  5810.      BYTES using zero-origin indexing.
  5811.  - Procedure: byte-set! BYTES K BYTE
  5812.      K must be a valid index of BYTES%, and BYTE must be a small
  5813.      integer.  `Byte-set!' stores BYTE in element K of BYTES and
  5814.      returns an unspecified value.
  5815.  - Function: make-bytes K
  5816.  - Function: make-bytes K BYTE
  5817.      `Make-bytes' returns a newly allocated byte-array of length K.  If
  5818.      BYTE is given, then all elements of the byte-array are initialized
  5819.      to BYTE, otherwise the contents of the byte-array are unspecified.
  5820.  - Function: bytes-length BYTES
  5821.      `bytes-length' returns length of byte-array BYTES.
  5822.  - Function: write-byte BYTE
  5823.  - Function: write-byte BYTE PORT
  5824.      Writes the byte BYTE (not an external representation of the byte)
  5825.      to the given PORT and returns an unspecified value.  The PORT
  5826.      argument may be omitted, in which case it defaults to the value
  5827.      returned by `current-output-port'.
  5828.  - Function: read-byte
  5829.  - Function: read-byte PORT
  5830.      Returns the next byte available from the input PORT, updating the
  5831.      PORT to point to the following byte.  If no more bytes are
  5832.      available, an end of file object is returned.  PORT may be
  5833.      omitted, in which case it defaults to the value returned by
  5834.      `current-input-port'.
  5835.  - Function: bytes BYTE ...
  5836.      Returns a newly allocated byte-array composed of the arguments.
  5837.  - Function: bytes->list BYTES
  5838.  - Function: list->bytes BYTES
  5839.      `Bytes->list' returns a newly allocated list of the bytes that
  5840.      make up the given byte-array.  `List->bytes' returns a newly
  5841.      allocated byte-array formed from the small integers in the list
  5842.      BYTES. `Bytes->list' and `list->bytes' are inverses so far as
  5843.      `equal?' is concerned.
  5844. File: slib.info,  Node: Collections,  Next: Dynamic Data Type,  Prev: Byte,  Up: Data Structures
  5845. Collections
  5846. -----------
  5847.   `(require 'collect)'
  5848.   Routines for managing collections.  Collections are aggregate data
  5849. structures supporting iteration over their elements, similar to the
  5850. Dylan(TM) language, but with a different interface.  They have
  5851. "elements" indexed by corresponding "keys", although the keys may be
  5852. implicit (as with lists).
  5853.   New types of collections may be defined as YASOS objects (*Note
  5854. Yasos::).  They must support the following operations:
  5855.    * `(collection? SELF)' (always returns `#t');
  5856.    * `(size SELF)' returns the number of elements in the collection;
  5857.    * `(print SELF PORT)' is a specialized print operation for the
  5858.      collection which prints a suitable representation on the given
  5859.      PORT or returns it as a string if PORT is `#t';
  5860.    * `(gen-elts SELF)' returns a thunk which on successive invocations
  5861.      yields elements of SELF in order or gives an error if it is
  5862.      invoked more than `(size SELF)' times;
  5863.    * `(gen-keys SELF)' is like `gen-elts', but yields the collection's
  5864.      keys in order.
  5865.   They might support specialized `for-each-key' and `for-each-elt'
  5866. operations.
  5867.  - Function: collection? OBJ
  5868.      A predicate, true initially of lists, vectors and strings.  New
  5869.      sorts of collections must answer `#t' to `collection?'.
  5870.  - Procedure: map-elts PROC . COLLECTIONS
  5871.  - Procedure: do-elts PROC . COLLECTIONS
  5872.      PROC is a procedure taking as many arguments as there are
  5873.      COLLECTIONS (at least one).  The COLLECTIONS are iterated over in
  5874.      their natural order and PROC is applied to the elements yielded by
  5875.      each iteration in turn.  The order in which the arguments are
  5876.      supplied corresponds to te order in which the COLLECTIONS appear.
  5877.      `do-elts' is used when only side-effects of PROC are of interest
  5878.      and its return value is unspecified.  `map-elts' returns a
  5879.      collection (actually a vector) of the results of the applications
  5880.      of PROC.
  5881.      Example:
  5882.           (map-elts + (list 1 2 3) (vector 1 2 3))
  5883.              => #(2 4 6)
  5884.  - Procedure: map-keys PROC . COLLECTIONS
  5885.  - Procedure: do-keys PROC . COLLECTIONS
  5886.      These are analogous to `map-elts' and `do-elts', but each
  5887.      iteration is over the COLLECTIONS' *keys* rather than their
  5888.      elements.
  5889.      Example:
  5890.           (map-keys + (list 1 2 3) (vector 1 2 3))
  5891.              => #(0 2 4)
  5892.  - Procedure: for-each-key COLLECTION PROC
  5893.  - Procedure: for-each-elt COLLECTION PROC
  5894.      These are like `do-keys' and `do-elts' but only for a single
  5895.      collection; they are potentially more efficient.
  5896.  - Function: reduce PROC SEED . COLLECTIONS
  5897.      A generalization of the list-based `comlist:reduce-init' (*Note
  5898.      Lists as sequences::) to collections which will shadow the
  5899.      list-based version if `(require 'collect)' follows `(require
  5900.      'common-list-functions)' (*Note Common List Functions::).
  5901.      Examples:
  5902.           (reduce + 0 (vector 1 2 3))
  5903.              => 6
  5904.           (reduce union '() '((a b c) (b c d) (d a)))
  5905.              => (c b d a).
  5906.  - Function: any? PRED . COLLECTIONS
  5907.      A generalization of the list-based `some' (*Note Lists as
  5908.      sequences::) to collections.
  5909.      Example:
  5910.           (any? odd? (list 2 3 4 5))
  5911.              => #t
  5912.  - Function: every? PRED . COLLECTIONS
  5913.      A generalization of the list-based `every' (*Note Lists as
  5914.      sequences::) to collections.
  5915.      Example:
  5916.           (every? collection? '((1 2) #(1 2)))
  5917.              => #t
  5918.  - Function: empty? COLLECTION
  5919.      Returns `#t' iff there are no elements in COLLECTION.
  5920.      `(empty? COLLECTION) == (zero? (size COLLECTION))'
  5921.  - Function: size COLLECTION
  5922.      Returns the number of elements in COLLECTION.
  5923.  - Function: Setter LIST-REF
  5924.      See *Note Setters:: for a definition of "setter".  N.B.  `(setter
  5925.      list-ref)' doesn't work properly for element 0 of a list.
  5926.   Here is a sample collection: `simple-table' which is also a `table'.
  5927.      (define-predicate TABLE?)
  5928.      (define-operation (LOOKUP table key failure-object))
  5929.      (define-operation (ASSOCIATE! table key value)) ;; returns key
  5930.      (define-operation (REMOVE! table key))          ;; returns value
  5931.      
  5932.      (define (MAKE-SIMPLE-TABLE)
  5933.        (let ( (table (list)) )
  5934.          (object
  5935.           ;; table behaviors
  5936.           ((TABLE? self) #t)
  5937.           ((SIZE self) (size table))
  5938.           ((PRINT self port) (format port "#<SIMPLE-TABLE>"))
  5939.           ((LOOKUP self key failure-object)
  5940.            (cond
  5941.             ((assq key table) => cdr)
  5942.             (else failure-object)
  5943.             ))
  5944.           ((ASSOCIATE! self key value)
  5945.            (cond
  5946.             ((assq key table)
  5947.              => (lambda (bucket) (set-cdr! bucket value) key))
  5948.             (else
  5949.              (set! table (cons (cons key value) table))
  5950.              key)
  5951.             ))
  5952.           ((REMOVE! self key);; returns old value
  5953.            (cond
  5954.             ((null? table) (slib:error "TABLE:REMOVE! Key not found: " key))
  5955.             ((eq? key (caar table))
  5956.              (let ( (value (cdar table)) )
  5957.                (set! table (cdr table))
  5958.                value)
  5959.              )
  5960.             (else
  5961.              (let loop ( (last table) (this (cdr table)) )
  5962.                (cond
  5963.                 ((null? this)
  5964.                  (slib:error "TABLE:REMOVE! Key not found: " key))
  5965.                 ((eq? key (caar this))
  5966.                  (let ( (value (cdar this)) )
  5967.                    (set-cdr! last (cdr this))
  5968.                    value)
  5969.                  )
  5970.                 (else
  5971.                  (loop (cdr last) (cdr this)))
  5972.                 ) ) )
  5973.             ))
  5974.           ;; collection behaviors
  5975.           ((COLLECTION? self) #t)
  5976.           ((GEN-KEYS self) (collect:list-gen-elts (map car table)))
  5977.           ((GEN-ELTS self) (collect:list-gen-elts (map cdr table)))
  5978.           ((FOR-EACH-KEY self proc)
  5979.            (for-each (lambda (bucket) (proc (car bucket))) table)
  5980.            )
  5981.           ((FOR-EACH-ELT self proc)
  5982.            (for-each (lambda (bucket) (proc (cdr bucket))) table)
  5983.            )
  5984.           ) ) )
  5985. File: slib.info,  Node: Dynamic Data Type,  Next: Hash Tables,  Prev: Collections,  Up: Data Structures
  5986. Dynamic Data Type
  5987. -----------------
  5988.   `(require 'dynamic)'
  5989.  - Function: make-dynamic OBJ
  5990.      Create and returns a new "dynamic" whose global value is OBJ.
  5991.  - Function: dynamic? OBJ
  5992.      Returns true if and only if OBJ is a dynamic.  No object
  5993.      satisfying `dynamic?' satisfies any of the other standard type
  5994.      predicates.
  5995.  - Function: dynamic-ref DYN
  5996.      Return the value of the given dynamic in the current dynamic
  5997.      environment.
  5998.  - Procedure: dynamic-set! DYN OBJ
  5999.      Change the value of the given dynamic to OBJ in the current
  6000.      dynamic environment.  The returned value is unspecified.
  6001.  - Function: call-with-dynamic-binding DYN OBJ THUNK
  6002.      Invoke and return the value of the given thunk in a new, nested
  6003.      dynamic environment in which the given dynamic has been bound to a
  6004.      new location whose initial contents are the value OBJ.  This
  6005.      dynamic environment has precisely the same extent as the
  6006.      invocation of the thunk and is thus captured by continuations
  6007.      created within that invocation and re-established by those
  6008.      continuations when they are invoked.
  6009.   The `dynamic-bind' macro is not implemented.
  6010. File: slib.info,  Node: Hash Tables,  Next: Hashing,  Prev: Dynamic Data Type,  Up: Data Structures
  6011. Hash Tables
  6012. -----------
  6013.   `(require 'hash-table)'
  6014.  - Function: predicate->hash PRED
  6015.      Returns a hash function (like `hashq', `hashv', or `hash')
  6016.      corresponding to the equality predicate PRED.  PRED should be
  6017.      `eq?', `eqv?', `equal?', `=', `char=?', `char-ci=?', `string=?', or
  6018.      `string-ci=?'.
  6019.   A hash table is a vector of association lists.
  6020.  - Function: make-hash-table K
  6021.      Returns a vector of K empty (association) lists.
  6022.   Hash table functions provide utilities for an associative database.
  6023. These functions take an equality predicate, PRED, as an argument.  PRED
  6024. should be `eq?', `eqv?', `equal?', `=', `char=?', `char-ci=?',
  6025. `string=?', or `string-ci=?'.
  6026.  - Function: predicate->hash-asso PRED
  6027.      Returns a hash association function of 2 arguments, KEY and
  6028.      HASHTAB, corresponding to PRED.  The returned function returns a
  6029.      key-value pair whose key is PRED-equal to its first argument or
  6030.      `#f' if no key in HASHTAB is PRED-equal to the first argument.
  6031.  - Function: hash-inquirer PRED
  6032.      Returns a procedure of 3 arguments, `hashtab' and `key', which
  6033.      returns the value associated with `key' in `hashtab' or `#f' if
  6034.      key does not appear in `hashtab'.
  6035.  - Function: hash-associator PRED
  6036.      Returns a procedure of 3 arguments, HASHTAB, KEY, and VALUE, which
  6037.      modifies HASHTAB so that KEY and VALUE associated.  Any previous
  6038.      value associated with KEY will be lost.
  6039.  - Function: hash-remover PRED
  6040.      Returns a procedure of 2 arguments, HASHTAB and KEY, which
  6041.      modifies HASHTAB so that the association whose key is KEY is
  6042.      removed.
  6043.  - Function: hash-map PROC HASH-TABLE
  6044.      Returns a new hash table formed by mapping PROC over the keys and
  6045.      values of HASH-TABLE.  PROC must be a function of 2 arguments
  6046.      which returns the new value part.
  6047.  - Function: hash-for-each PROC HASH-TABLE
  6048.      Applies PROC to each pair of keys and values of HASH-TABLE.  PROC
  6049.      must be a function of 2 arguments.  The returned value is
  6050.      unspecified.
  6051. File: slib.info,  Node: Hashing,  Next: Object,  Prev: Hash Tables,  Up: Data Structures
  6052.                                                                               |
  6053. Hashing
  6054. -------
  6055.   `(require 'hash)'
  6056.   These hashing functions are for use in quickly classifying objects.
  6057. Hash tables use these functions.
  6058.  - Function: hashq OBJ K
  6059.  - Function: hashv OBJ K
  6060.  - Function: hash OBJ K
  6061.      Returns an exact non-negative integer less than K.  For each
  6062.      non-negative integer less than K there are arguments OBJ for which
  6063.      the hashing functions applied to OBJ and K returns that integer.
  6064.      For `hashq', `(eq? obj1 obj2)' implies `(= (hashq obj1 k) (hashq
  6065.      obj2))'.
  6066.      For `hashv', `(eqv? obj1 obj2)' implies `(= (hashv obj1 k) (hashv
  6067.      obj2))'.
  6068.      For `hash', `(equal? obj1 obj2)' implies `(= (hash obj1 k) (hash
  6069.      obj2))'.
  6070.      `hash', `hashv', and `hashq' return in time bounded by a constant.
  6071.      Notice that items having the same `hash' implies the items have
  6072.      the same `hashv' implies the items have the same `hashq'.
  6073.   `(require 'sierpinski)'
  6074.  - Function: make-sierpinski-indexer MAX-COORDINATE
  6075.      Returns a procedure (eg hash-function) of 2 numeric arguments which
  6076.      preserves *nearness* in its mapping from NxN to N.
  6077.      MAX-COORDINATE is the maximum coordinate (a positive integer) of a
  6078.      population of points.  The returned procedures is a function that
  6079.      takes the x and y coordinates of a point, (non-negative integers)
  6080.      and returns an integer corresponding to the relative position of
  6081.      that point along a Sierpinski curve.  (You can think of this as
  6082.      computing a (pseudo-) inverse of the Sierpinski spacefilling
  6083.      curve.)
  6084.      Example use: Make an indexer (hash-function) for integer points
  6085.      lying in square of integer grid points [0,99]x[0,99]:
  6086.           (define space-key (make-sierpinski-indexer 100))
  6087.      Now let's compute the index of some points:
  6088.           (space-key 24 78)               => 9206
  6089.           (space-key 23 80)               => 9172
  6090.      Note that locations (24, 78) and (23, 80) are near in index and
  6091.      therefore, because the Sierpinski spacefilling curve is
  6092.      continuous, we know they must also be near in the plane.  Nearness
  6093.      in the plane does not, however, necessarily correspond to nearness
  6094.      in index, although it *tends* to be so.
  6095.      Example applications:
  6096.         * Sort points by Sierpinski index to get heuristic solution to
  6097.           *travelling salesman problem*.  For details of performance,
  6098.           see L. Platzman and J. Bartholdi, "Spacefilling curves and the
  6099.           Euclidean travelling salesman problem", JACM 36(4):719-737
  6100.           (October 1989) and references therein.
  6101.         * Use Sierpinski index as key by which to store 2-dimensional
  6102.           data in a 1-dimensional data structure (such as a table).
  6103.           Then locations that are near each other in 2-d space will
  6104.           tend to be near each other in 1-d data structure; and
  6105.           locations that are near in 1-d data structure will be near in
  6106.           2-d space.  This can significantly speed retrieval from
  6107.           secondary storage because contiguous regions in the plane
  6108.           will tend to correspond to contiguous regions in secondary
  6109.           storage.  (This is a standard technique for managing CAD/CAM
  6110.           or geographic data.)
  6111.   `(require 'soundex)'
  6112.  - Function: soundex NAME
  6113.      Computes the *soundex* hash of NAME.  Returns a string of an
  6114.      initial letter and up to three digits between 0 and 6.  Soundex
  6115.      supposedly has the property that names that sound similar in normal
  6116.      English pronunciation tend to map to the same key.
  6117.      Soundex was a classic algorithm used for manual filing of personal
  6118.      records before the advent of computers.  It performs adequately for
  6119.      English names but has trouble with other nationalities.
  6120.      See Knuth, Vol. 3 `Sorting and searching', pp 391-2
  6121.      To manage unusual inputs, `soundex' omits all non-alphabetic
  6122.      characters.  Consequently, in this implementation:
  6123.           (soundex <string of blanks>)    => ""
  6124.           (soundex "")                    => ""
  6125.      Examples from Knuth:
  6126.           (map soundex '("Euler" "Gauss" "Hilbert" "Knuth"
  6127.                                  "Lloyd" "Lukasiewicz"))
  6128.                   => ("E460" "G200" "H416" "K530" "L300" "L222")
  6129.           
  6130.           (map soundex '("Ellery" "Ghosh" "Heilbronn" "Kant"
  6131.                                   "Ladd" "Lissajous"))
  6132.                   => ("E460" "G200" "H416" "K530" "L300" "L222")
  6133.      Some cases in which the algorithm fails (Knuth):
  6134.           (map soundex '("Rogers" "Rodgers"))     => ("R262" "R326")
  6135.           
  6136.           (map soundex '("Sinclair" "St. Clair")) => ("S524" "S324")
  6137.           
  6138.           (map soundex '("Tchebysheff" "Chebyshev")) => ("T212" "C121")
  6139. File: slib.info,  Node: Object,  Next: Priority Queues,  Prev: Hashing,  Up: Data Structures
  6140.                                                                               |
  6141. Macroless Object System                                                       |
  6142. -----------------------                                                       |
  6143.                                                                               |
  6144.   `(require 'object)'                                                         |
  6145.                                                                               |
  6146.   This is the Macroless Object System written by Wade Humeniuk                |
  6147. (whumeniu@datap.ca).  Conceptual Tributes: *Note Yasos::, MacScheme's         |
  6148. %object, CLOS, Lack of R4RS macros.                                           |
  6149.                                                                               |
  6150. Concepts                                                                      |
  6151. --------                                                                      |
  6152.                                                                               |
  6153. OBJECT                                                                        |
  6154.      An object is an ordered association-list (by `eq?') of methods           |
  6155.      (procedures).  Methods can be added (`make-method!'), deleted            |
  6156.      (`unmake-method!') and retrieved (`get-method').  Objects may            |
  6157.      inherit methods from other objects.  The object binds to the             |
  6158.      environment it was created in, allowing closures to be used to           |
  6159.      hide private procedures and data.                                        |
  6160.                                                                               |
  6161. GENERIC-METHOD                                                                |
  6162.      A generic-method associates (in terms of `eq?') object's method.         |
  6163.      This allows scheme function style to be used for objects.  The           |
  6164.      calling scheme for using a generic method is `(generic-method            |
  6165.      object param1 param2 ...)'.                                              |
  6166.                                                                               |
  6167. METHOD                                                                        |
  6168.      A method is a procedure that exists in the object.  To use a method      |
  6169.      get-method must be called to look-up the method.  Generic methods        |
  6170.      implement the get-method functionality.  Methods may be added to an      |
  6171.      object associated with any scheme obj in terms of eq?                    |
  6172.                                                                               |
  6173. GENERIC-PREDICATE                                                             |
  6174.      A generic method that returns a boolean value for any scheme obj.        |
  6175.                                                                               |
  6176. PREDICATE                                                                     |
  6177.      A object's method asscociated with a generic-predicate. Returns          |
  6178.      `#t'.                                                                    |
  6179.                                                                               |
  6180. Procedures                                                                    |
  6181. ----------                                                                    |
  6182.                                                                               |
  6183.  - Function: make-object ANCESTOR ...                                         |
  6184.      Returns an object.  Current object implementation is a tagged            |
  6185.      vector.  ANCESTORs are optional and must be objects in terms of          |
  6186.      object?.  ANCESTORs methods are included in the object.  Multiple        |
  6187.      ANCESTORs might associate the same generic-method with a method.         |
  6188.      In this case the method of the ANCESTOR first appearing in the           |
  6189.      list is the one returned by `get-method'.                                |
  6190.                                                                               |
  6191.  - Function: object? OBJ                                                      |
  6192.      Returns boolean value whether OBJ was created by make-object.            |
  6193.                                                                               |
  6194.  - Function: make-generic-method EXCEPTION-PROCEDURE                          |
  6195.      Returns a procedure which be associated with an object's methods.        |
  6196.      If EXCEPTION-PROCEDURE is specified then it is used to process           |
  6197.      non-objects.                                                             |
  6198.                                                                               |
  6199.  - Function: make-generic-predicate                                           |
  6200.      Returns a boolean procedure for any scheme object.                       |
  6201.                                                                               |
  6202.  - Function: make-method! OBJECT GENERIC-METHOD METHOD                        |
  6203.      Associates METHOD to the GENERIC-METHOD in the object.  The METHOD       |
  6204.      overrides any previous association with the GENERIC-METHOD within        |
  6205.      the object.  Using `unmake-method!'  will restore the object's           |
  6206.      previous association with the GENERIC-METHOD.  METHOD must be a          |
  6207.      procedure.                                                               |
  6208.                                                                               |
  6209.  - Function: make-predicate! OBJECT GENERIC-PRECIATE                          |
  6210.      Makes a predicate method associated with the GENERIC-PREDICATE.          |
  6211.                                                                               |
  6212.  - Function: unmake-method! OBJECT GENERIC-METHOD                             |
  6213.      Removes an object's association with a GENERIC-METHOD .                  |
  6214.                                                                               |
  6215.  - Function: get-method OBJECT GENERIC-METHOD                                 |
  6216.      Returns the object's method associated (if any) with the                 |
  6217.      GENERIC-METHOD.  If no associated method exists an error is              |
  6218.      flagged.                                                                 |
  6219.                                                                               |
  6220. Examples                                                                      |
  6221. --------                                                                      |
  6222.                                                                               |
  6223.      (require 'object)                                                        |
  6224.                                                                               |
  6225.      (define instantiate (make-generic-method))                               |
  6226.                                                                               |
  6227.      (define (make-instance-object . ancestors)                               |
  6228.        (define self (apply make-object                                        |
  6229.                            (map (lambda (obj) (instantiate obj)) ancestors))) |
  6230.        (make-method! self instantiate (lambda (self) self))                   |
  6231.        self)                                                                  |
  6232.                                                                               |
  6233.      (define who (make-generic-method))                                       |
  6234.      (define imigrate! (make-generic-method))                                 |
  6235.      (define emigrate! (make-generic-method))                                 |
  6236.      (define describe (make-generic-method))                                  |
  6237.      (define name (make-generic-method))                                      |
  6238.      (define address (make-generic-method))                                   |
  6239.      (define members (make-generic-method))                                   |
  6240.                                                                               |
  6241.      (define society                                                          |
  6242.        (let ()                                                                |
  6243.          (define self (make-instance-object))                                 |
  6244.          (define population '())                                              |
  6245.          (make-method! self imigrate!                                         |
  6246.                        (lambda (new-person)                                   |
  6247.                          (if (not (eq? new-person self))                      |
  6248.                              (set! population (cons new-person population)))))
  6249.          (make-method! self emigrate!                                         |
  6250.                        (lambda (person)                                       |
  6251.                          (if (not (eq? person self))                          |
  6252.                              (set! population                                 |
  6253.                                    (comlist:remove-if (lambda (member)        |
  6254.                                                         (eq? member person))  |
  6255.                                                       population)))))         |
  6256.          (make-method! self describe                                          |
  6257.                        (lambda (self)                                         |
  6258.                          (map (lambda (person) (describe person)) population)))
  6259.          (make-method! self who                                               |
  6260.                        (lambda (self) (map (lambda (person) (name person))    |
  6261.                                            population)))                      |
  6262.          (make-method! self members (lambda (self) population))               |
  6263.          self))                                                               |
  6264.                                                                               |
  6265.      (define (make-person %name %address)                                     |
  6266.        (define self (make-instance-object society))                           |
  6267.        (make-method! self name (lambda (self) %name))                         |
  6268.        (make-method! self address (lambda (self) %address))                   |
  6269.        (make-method! self who (lambda (self) (name self)))                    |
  6270.        (make-method! self instantiate                                         |
  6271.                      (lambda (self)                                           |
  6272.                        (make-person (string-append (name self) "-son-of")     |
  6273.                                     %address)))                               |
  6274.        (make-method! self describe                                            |
  6275.                      (lambda (self) (list (name self) (address self))))       |
  6276.        (imigrate! self)                                                       |
  6277.        self)                                                                  |
  6278.                                                                               |
  6279. Inverter Documentation                                                        |
  6280. ......................                                                        |
  6281.                                                                               |
  6282.   Inheritance:                                                                |
  6283.              <inverter>::(<number> <description>)                             |
  6284.   Generic-methods                                                             |
  6285.              <inverter>::value      => <number>::value                        |
  6286.              <inverter>::set-value! => <number>::set-value!                   |
  6287.              <inverter>::describe   => <description>::describe                |
  6288.              <inverter>::help                                                 |
  6289.              <inverter>::invert                                               |
  6290.              <inverter>::inverter?                                            |
  6291.                                                                               |
  6292. Number Documention                                                            |
  6293. ..................                                                            |
  6294.                                                                               |
  6295.   Inheritance                                                                 |
  6296.              <number>::()                                                     |
  6297.   Slots                                                                       |
  6298.              <number>::<x>                                                    |
  6299.   Generic Methods                                                             |
  6300.              <number>::value                                                  |
  6301.              <number>::set-value!                                             |
  6302.                                                                               |
  6303. Inverter code                                                                 |
  6304. .............                                                                 |
  6305.                                                                               |
  6306.      (require 'object)                                                        |
  6307.                                                                               |
  6308.      (define value (make-generic-method (lambda (val) val)))                  |
  6309.      (define set-value! (make-generic-method))                                |
  6310.      (define invert (make-generic-method                                      |
  6311.                      (lambda (val)                                            |
  6312.                        (if (number? val)                                      |
  6313.                            (/ 1 val)                                          |
  6314.                            (error "Method not supported:" val)))))            |
  6315.      (define noop (make-generic-method))                                      |
  6316.      (define inverter? (make-generic-predicate))                              |
  6317.      (define describe (make-generic-method))                                  |
  6318.      (define help (make-generic-method))                                      |
  6319.                                                                               |
  6320.      (define (make-number x)                                                  |
  6321.        (define self (make-object))                                            |
  6322.        (make-method! self value (lambda (this) x))                            |
  6323.        (make-method! self set-value!                                          |
  6324.                      (lambda (this new-value) (set! x new-value)))            |
  6325.        self)                                                                  |
  6326.                                                                               |
  6327.      (define (make-description str)                                           |
  6328.        (define self (make-object))                                            |
  6329.        (make-method! self describe (lambda (this) str))                       |
  6330.        (make-method! self help (lambda (this) "Help not available"))          |
  6331.        self)                                                                  |
  6332.                                                                               |
  6333.      (define (make-inverter)                                                  |
  6334.        (let* ((self (make-object                                              |
  6335.                      (make-number 1)                                          |
  6336.                      (make-description "A number which can be inverted")))    |
  6337.               (<value> (get-method self value)))                              |
  6338.          (make-method! self invert (lambda (self) (/ 1 (<value> self))))      |
  6339.          (make-predicate! self inverter?)                                     |
  6340.          (unmake-method! self help)                                           |
  6341.          (make-method! self help                                              |
  6342.                        (lambda (self)                                         |
  6343.                          (display "Inverter Methods:") (newline)              |
  6344.                          (display "  (value inverter) ==> n") (newline)))     |
  6345.          self))                                                               |
  6346.                                                                               |
  6347.      ;;;; Try it out                                                          |
  6348.                                                                               |
  6349.      (define invert! (make-generic-method))                                   |
  6350.                                                                               |
  6351.      (define x (make-inverter))                                               |
  6352.                                                                               |
  6353.      (make-method! x invert! (lambda (x) (set-value! x (/ 1 (value x)))))     |
  6354.                                                                               |
  6355.      (value x)                       => 1                                     |
  6356.      (set-value! x 33)               => undefined                             |
  6357.      (invert! x)                     => undefined                             |
  6358.      (value x)                       => 1/33                                  |
  6359.                                                                               |
  6360.      (unmake-method! x invert!)      => undefined                             |
  6361.                                                                               |
  6362.      (invert! x)                     error-->  ERROR: Method not supported: x |
  6363.                                                                               |
  6364. File: slib.info,  Node: Priority Queues,  Next: Queues,  Prev: Object,  Up: Data Structures
  6365.                                                                               |
  6366. Priority Queues
  6367. ---------------
  6368.   `(require 'priority-queue)'
  6369.  - Function: make-heap PRED<?
  6370.      Returns a binary heap suitable which can be used for priority queue
  6371.      operations.
  6372.  - Function: heap-length HEAP
  6373.      Returns the number of elements in HEAP.
  6374.  - Procedure: heap-insert! HEAP ITEM
  6375.      Inserts ITEM into HEAP.  ITEM can be inserted multiple times.  The
  6376.      value returned is unspecified.
  6377.  - Function: heap-extract-max! HEAP
  6378.      Returns the item which is larger than all others according to the
  6379.      PRED<? argument to `make-heap'.  If there are no items in HEAP, an
  6380.      error is signaled.
  6381.   The algorithm for priority queues was taken from `Introduction to
  6382. Algorithms' by T. Cormen, C. Leiserson, R. Rivest.  1989 MIT Press.
  6383. File: slib.info,  Node: Queues,  Next: Records,  Prev: Priority Queues,  Up: Data Structures
  6384. Queues
  6385. ------
  6386.   `(require 'queue)'
  6387.   A "queue" is a list where elements can be added to both the front and
  6388. rear, and removed from the front (i.e., they are what are often called
  6389. "dequeues").  A queue may also be used like a stack.
  6390.  - Function: make-queue
  6391.      Returns a new, empty queue.
  6392.  - Function: queue? OBJ
  6393.      Returns `#t' if OBJ is a queue.
  6394.  - Function: queue-empty? Q
  6395.      Returns `#t' if the queue Q is empty.
  6396.  - Procedure: queue-push! Q DATUM
  6397.      Adds DATUM to the front of queue Q.
  6398.  - Procedure: enquque! Q DATUM
  6399.      Adds DATUM to the rear of queue Q.
  6400.   All of the following functions raise an error if the queue Q is empty.
  6401.  - Function: queue-front Q
  6402.      Returns the datum at the front of the queue Q.
  6403.  - Function: queue-rear Q
  6404.      Returns the datum at the rear of the queue Q.
  6405.  - Prcoedure: queue-pop! Q
  6406.  - Procedure: dequeue! Q
  6407.      Both of these procedures remove and return the datum at the front
  6408.      of the queue.  `queue-pop!' is used to suggest that the queue is
  6409.      being used like a stack.
  6410. File: slib.info,  Node: Records,  Next: Structures,  Prev: Queues,  Up: Data Structures
  6411. Records
  6412. -------
  6413.   `(require 'record)'
  6414.   The Record package provides a facility for user to define their own
  6415. record data types.
  6416.  - Function: make-record-type TYPE-NAME FIELD-NAMES
  6417.      Returns a "record-type descriptor", a value representing a new data
  6418.      type disjoint from all others.  The TYPE-NAME argument must be a
  6419.      string, but is only used for debugging purposes (such as the
  6420.      printed representation of a record of the new type).  The
  6421.      FIELD-NAMES argument is a list of symbols naming the "fields" of a
  6422.      record of the new type.  It is an error if the list contains any
  6423.      duplicates.  It is unspecified how record-type descriptors are
  6424.      represented.
  6425.  - Function: record-constructor RTD [FIELD-NAMES]
  6426.      Returns a procedure for constructing new members of the type
  6427.      represented by RTD.  The returned procedure accepts exactly as
  6428.      many arguments as there are symbols in the given list,
  6429.      FIELD-NAMES; these are used, in order, as the initial values of
  6430.      those fields in a new record, which is returned by the constructor
  6431.      procedure.  The values of any fields not named in that list are
  6432.      unspecified.  The FIELD-NAMES argument defaults to the list of
  6433.      field names in the call to `make-record-type' that created the
  6434.      type represented by RTD; if the FIELD-NAMES argument is provided,
  6435.      it is an error if it contains any duplicates or any symbols not in
  6436.      the default list.
  6437.  - Function: record-predicate RTD
  6438.      Returns a procedure for testing membership in the type represented
  6439.      by RTD.  The returned procedure accepts exactly one argument and
  6440.      returns a true value if the argument is a member of the indicated
  6441.      record type; it returns a false value otherwise.
  6442.  - Function: record-accessor RTD FIELD-NAME
  6443.      Returns a procedure for reading the value of a particular field of
  6444.      a member of the type represented by RTD.  The returned procedure
  6445.      accepts exactly one argument which must be a record of the
  6446.      appropriate type; it returns the current value of the field named
  6447.      by the symbol FIELD-NAME in that record.  The symbol FIELD-NAME
  6448.      must be a member of the list of field-names in the call to
  6449.      `make-record-type' that created the type represented by RTD.
  6450.  - Function: record-modifier RTD FIELD-NAME
  6451.      Returns a procedure for writing the value of a particular field of
  6452.      a member of the type represented by RTD.  The returned procedure
  6453.      accepts exactly two arguments: first, a record of the appropriate
  6454.      type, and second, an arbitrary Scheme value; it modifies the field
  6455.      named by the symbol FIELD-NAME in that record to contain the given
  6456.      value.  The returned value of the modifier procedure is
  6457.      unspecified.  The symbol FIELD-NAME must be a member of the list
  6458.      of field-names in the call to `make-record-type' that created the
  6459.      type represented by RTD.
  6460.   In May of 1996, as a product of discussion on the `rrrs-authors'
  6461. mailing list, I rewrote `record.scm' to portably implement type
  6462. disjointness for record data types.
  6463.   As long as an implementation's procedures are opaque and the `record'
  6464. code is loaded before other programs, this will give disjoint record
  6465. types which are unforgeable and incorruptible by R4RS procedures.
  6466.   As a consequence, the procedures `record?', `record-type-descriptor',
  6467. `record-type-name'.and `record-type-field-names' are no longer
  6468. supported.
  6469. File: slib.info,  Node: Structures,  Prev: Records,  Up: Data Structures
  6470. Structures
  6471. ----------
  6472.   `(require 'struct)' (uses defmacros)
  6473.   `defmacro's which implement "records" from the book `Essentials of
  6474. Programming Languages' by Daniel P. Friedman, M.  Wand and C.T. Haynes.
  6475. Copyright 1992 Jeff Alexander, Shinnder Lee, and Lewis Patterson
  6476.   Matthew McDonald <mafm@cs.uwa.edu.au> added field setters.
  6477.  - Macro: define-record TAG (VAR1 VAR2 ...)
  6478.      Defines several functions pertaining to record-name TAG:
  6479.       - Function: make-TAG VAR1 VAR2 ...
  6480.       - Function: TAG? OBJ
  6481.       - Function: TAG->VAR1 OBJ
  6482.       - Function: TAG->VAR2 OBJ
  6483.      ...
  6484.       - Function: set-TAG-VAR1! OBJ VAL
  6485.       - Function: set-TAG-VAR2! OBJ VAL
  6486.      ...
  6487.      Here is an example of its use.
  6488.           (define-record term (operator left right))
  6489.           => #<unspecified>
  6490.           (define foo (make-term 'plus  1 2))
  6491.           => foo
  6492.           (term->left foo)
  6493.           => 1
  6494.           (set-term-left! foo 2345)
  6495.           => #<unspecified>
  6496.           (term->left foo)
  6497.           => 2345
  6498.  - Macro: variant-case EXP (TAG (VAR1 VAR2 ...) BODY) ...
  6499.      executes the following for the matching clause:
  6500.           ((lambda (VAR1 VAR ...) BODY)
  6501.              (TAG->VAR1 EXP)
  6502.              (TAG->VAR2 EXP) ...)
  6503. File: slib.info,  Node: Procedures,  Next: Standards Support,  Prev: Data Structures,  Up: Other Packages
  6504. Procedures
  6505. ==========
  6506.   Anything that doesn't fall neatly into any of the other categories
  6507. winds up here.
  6508. * Menu:
  6509. * Common List Functions::       'common-list-functions
  6510. * Tree Operations::             'tree
  6511. * Chapter Ordering::            'chapter-order
  6512. * Sorting::                     'sort
  6513. * Topological Sort::            Keep your socks on.
  6514. * String-Case::                 'string-case
  6515. * String Ports::                'string-port
  6516. * String Search::               Also Search from a Port.
  6517. * Line I/O::                    'line-i/o
  6518. * Multi-Processing::            'process
  6519. File: slib.info,  Node: Common List Functions,  Next: Tree Operations,  Prev: Procedures,  Up: Procedures
  6520. Common List Functions
  6521. ---------------------
  6522.   `(require 'common-list-functions)'
  6523.   The procedures below follow the Common LISP equivalents apart from
  6524. optional arguments in some cases.
  6525. * Menu:
  6526. * List construction::
  6527. * Lists as sets::
  6528. * Lists as sequences::
  6529. * Destructive list operations::
  6530. * Non-List functions::
  6531. File: slib.info,  Node: List construction,  Next: Lists as sets,  Prev: Common List Functions,  Up: Common List Functions
  6532. List construction
  6533. .................
  6534.  - Function: make-list K . INIT
  6535.      `make-list' creates and returns a list of K elements.  If INIT is
  6536.      included, all elements in the list are initialized to INIT.
  6537.      Example:
  6538.           (make-list 3)
  6539.              => (#<unspecified> #<unspecified> #<unspecified>)
  6540.           (make-list 5 'foo)
  6541.              => (foo foo foo foo foo)
  6542.  - Function: list* X . Y
  6543.      Works like `list' except that the cdr of the last pair is the last
  6544.      argument unless there is only one argument, when the result is
  6545.      just that argument.  Sometimes called `cons*'.  E.g.:
  6546.           (list* 1)
  6547.              => 1
  6548.           (list* 1 2 3)
  6549.              => (1 2 . 3)
  6550.           (list* 1 2 '(3 4))
  6551.              => (1 2 3 4)
  6552.           (list* ARGS '())
  6553.              == (list ARGS)
  6554.  - Function: copy-list LST
  6555.      `copy-list' makes a copy of LST using new pairs and returns it.
  6556.      Only the top level of the list is copied, i.e., pairs forming
  6557.      elements of the copied list remain `eq?' to the corresponding
  6558.      elements of the original; the copy is, however, not `eq?' to the
  6559.      original, but is `equal?' to it.
  6560.      Example:
  6561.           (copy-list '(foo foo foo))
  6562.              => (foo foo foo)
  6563.           (define q '(foo bar baz bang))
  6564.           (define p q)
  6565.           (eq? p q)
  6566.              => #t
  6567.           (define r (copy-list q))
  6568.           (eq? q r)
  6569.              => #f
  6570.           (equal? q r)
  6571.              => #t
  6572.           (define bar '(bar))
  6573.           (eq? bar (car (copy-list (list bar 'foo))))
  6574.           => #t
  6575. File: slib.info,  Node: Lists as sets,  Next: Lists as sequences,  Prev: List construction,  Up: Common List Functions
  6576. Lists as sets
  6577. .............
  6578.   `eqv?' is used to test for membership by procedures which treat lists
  6579. as sets.
  6580.  - Function: adjoin E L
  6581.      `adjoin' returns the adjoint of the element E and the list L.
  6582.      That is, if E is in L, `adjoin' returns L, otherwise, it returns
  6583.      `(cons E L)'.
  6584.      Example:
  6585.           (adjoin 'baz '(bar baz bang))
  6586.              => (bar baz bang)
  6587.           (adjoin 'foo '(bar baz bang))
  6588.              => (foo bar baz bang)
  6589.  - Function: union L1 L2
  6590.      `union' returns the combination of L1 and L2.  Duplicates between
  6591.      L1 and L2 are culled.  Duplicates within L1 or within L2 may or
  6592.      may not be removed.
  6593.      Example:
  6594.           (union '(1 2 3 4) '(5 6 7 8))
  6595.              => (4 3 2 1 5 6 7 8)
  6596.           (union '(1 2 3 4) '(3 4 5 6))
  6597.              => (2 1 3 4 5 6)
  6598.  - Function: intersection L1 L2
  6599.      `intersection' returns all elements that are in both L1 and L2.
  6600.      Example:
  6601.           (intersection '(1 2 3 4) '(3 4 5 6))
  6602.              => (3 4)
  6603.           (intersection '(1 2 3 4) '(5 6 7 8))
  6604.              => ()
  6605.  - Function: set-difference L1 L2
  6606.      `set-difference' returns the union of all elements that are in L1
  6607.      but not in L2.
  6608.      Example:
  6609.           (set-difference '(1 2 3 4) '(3 4 5 6))
  6610.              => (1 2)
  6611.           (set-difference '(1 2 3 4) '(1 2 3 4 5 6))
  6612.              => ()
  6613.  - Function: member-if PRED LST
  6614.      `member-if' returns LST if `(PRED ELEMENT)' is `#t' for any
  6615.      ELEMENT in LST.  Returns `#f' if PRED does not apply to any
  6616.      ELEMENT in LST.
  6617.      Example:
  6618.           (member-if vector? '(1 2 3 4))
  6619.              => #f
  6620.           (member-if number? '(1 2 3 4))
  6621.              => (1 2 3 4)
  6622.  - Function: some PRED LST . MORE-LSTS
  6623.      PRED is a boolean function of as many arguments as there are list
  6624.      arguments to `some' i.e., LST plus any optional arguments.  PRED
  6625.      is applied to successive elements of the list arguments in order.
  6626.      `some' returns `#t' as soon as one of these applications returns
  6627.      `#t', and is `#f' if none returns `#t'.  All the lists should have
  6628.      the same length.
  6629.      Example:
  6630.           (some odd? '(1 2 3 4))
  6631.              => #t
  6632.           
  6633.           (some odd? '(2 4 6 8))
  6634.              => #f
  6635.           
  6636.           (some > '(2 3) '(1 4))
  6637.              => #f
  6638.  - Function: every PRED LST . MORE-LSTS
  6639.      `every' is analogous to `some' except it returns `#t' if every
  6640.      application of PRED is `#t' and `#f' otherwise.
  6641.      Example:
  6642.           (every even? '(1 2 3 4))
  6643.              => #f
  6644.           
  6645.           (every even? '(2 4 6 8))
  6646.              => #t
  6647.           
  6648.           (every > '(2 3) '(1 4))
  6649.              => #f
  6650.  - Function: notany PRED . LST
  6651.      `notany' is analogous to `some' but returns `#t' if no application
  6652.      of PRED returns `#t' or `#f' as soon as any one does.
  6653.  - Function: notevery PRED . LST
  6654.      `notevery' is analogous to `some' but returns `#t' as soon as an
  6655.      application of PRED returns `#f', and `#f' otherwise.
  6656.      Example:
  6657.           (notevery even? '(1 2 3 4))
  6658.              => #t
  6659.           
  6660.           (notevery even? '(2 4 6 8))
  6661.              => #f
  6662.  - Function: find-if PRED LST
  6663.      `find-if' searches for the first ELEMENT in LST such that `(PRED
  6664.      ELEMENT)' returns `#t'.  If it finds any such ELEMENT in LST,
  6665.      ELEMENT is returned.  Otherwise, `#f' is returned.
  6666.      Example:
  6667.           (find-if number? '(foo 1 bar 2))
  6668.              => 1
  6669.           
  6670.           (find-if number? '(foo bar baz bang))
  6671.              => #f
  6672.           
  6673.           (find-if symbol? '(1 2 foo bar))
  6674.              => foo
  6675.  - Function: remove ELT LST
  6676.      `remove' removes all occurrences of ELT from LST using `eqv?' to
  6677.      test for equality and returns everything that's left.  N.B.: other
  6678.      implementations (Chez, Scheme->C and T, at least) use `equal?' as
  6679.      the equality test.
  6680.      Example:
  6681.           (remove 1 '(1 2 1 3 1 4 1 5))
  6682.              => (2 3 4 5)
  6683.           
  6684.           (remove 'foo '(bar baz bang))
  6685.              => (bar baz bang)
  6686.  - Function: remove-if PRED LST
  6687.      `remove-if' removes all ELEMENTs from LST where `(PRED ELEMENT)'
  6688.      is `#t' and returns everything that's left.
  6689.      Example:
  6690.           (remove-if number? '(1 2 3 4))
  6691.              => ()
  6692.           
  6693.           (remove-if even? '(1 2 3 4 5 6 7 8))
  6694.              => (1 3 5 7)
  6695.  - Function: remove-if-not PRED LST
  6696.      `remove-if-not' removes all ELEMENTs from LST for which `(PRED
  6697.      ELEMENT)' is `#f' and returns everything that's left.
  6698.      Example:
  6699.           (remove-if-not number? '(foo bar baz))
  6700.              => ()
  6701.           (remove-if-not odd? '(1 2 3 4 5 6 7 8))
  6702.              => (1 3 5 7)
  6703.  - Function: has-duplicates? LST
  6704.      returns `#t' if 2 members of LST are `equal?', `#f' otherwise.
  6705.      Example:
  6706.           (has-duplicates? '(1 2 3 4))
  6707.              => #f
  6708.           
  6709.           (has-duplicates? '(2 4 3 4))
  6710.              => #t
  6711.   The procedure `remove-duplicates' uses `member' (rather than `memv').
  6712.  - Function: remove-duplicates LST
  6713.      returns a copy of LST with its duplicate members removed.
  6714.      Elements are considered duplicate if they are `equal?'.
  6715.      Example:
  6716.           (remove-duplicates '(1 2 3 4))
  6717.              => (4 3 2 1)
  6718.           
  6719.           (remove-duplicates '(2 4 3 4))
  6720.              => (3 4 2)
  6721. File: slib.info,  Node: Lists as sequences,  Next: Destructive list operations,  Prev: Lists as sets,  Up: Common List Functions
  6722. Lists as sequences
  6723. ..................
  6724.  - Function: position OBJ LST
  6725.      `position' returns the 0-based position of OBJ in LST, or `#f' if
  6726.      OBJ does not occur in LST.
  6727.      Example:
  6728.           (position 'foo '(foo bar baz bang))
  6729.              => 0
  6730.           (position 'baz '(foo bar baz bang))
  6731.              => 2
  6732.           (position 'oops '(foo bar baz bang))
  6733.              => #f
  6734.  - Function: reduce P LST
  6735.      `reduce' combines all the elements of a sequence using a binary
  6736.      operation (the combination is left-associative).  For example,
  6737.      using `+', one can add up all the elements.  `reduce' allows you to
  6738.      apply a function which accepts only two arguments to more than 2
  6739.      objects.  Functional programmers usually refer to this as "foldl".
  6740.      `collect:reduce' (*Note Collections::) provides a version of
  6741.      `collect' generalized to collections.
  6742.      Example:
  6743.           (reduce + '(1 2 3 4))
  6744.              => 10
  6745.           (define (bad-sum . l) (reduce + l))
  6746.           (bad-sum 1 2 3 4)
  6747.              == (reduce + (1 2 3 4))
  6748.              == (+ (+ (+ 1 2) 3) 4)
  6749.           => 10
  6750.           (bad-sum)
  6751.              == (reduce + ())
  6752.              => ()
  6753.           (reduce string-append '("hello" "cruel" "world"))
  6754.              == (string-append (string-append "hello" "cruel") "world")
  6755.              => "hellocruelworld"
  6756.           (reduce anything '())
  6757.              => ()
  6758.           (reduce anything '(x))
  6759.              => x
  6760.      What follows is a rather non-standard implementation of `reverse'
  6761.      in terms of `reduce' and a combinator elsewhere called "C".
  6762.           ;;; Contributed by Jussi Piitulainen (jpiitula@ling.helsinki.fi)
  6763.           
  6764.           (define commute
  6765.             (lambda (f)
  6766.               (lambda (x y)
  6767.                 (f y x))))
  6768.           
  6769.           (define reverse
  6770.             (lambda (args)
  6771.               (reduce-init (commute cons) '() args)))
  6772.  - Function: reduce-init P INIT LST
  6773.      `reduce-init' is the same as reduce, except that it implicitly
  6774.      inserts INIT at the start of the list.  `reduce-init' is preferred
  6775.      if you want to handle the null list, the one-element, and lists
  6776.      with two or more elements consistently.  It is common to use the
  6777.      operator's idempotent as the initializer.  Functional programmers
  6778.      usually call this "foldl".
  6779.      Example:
  6780.           (define (sum . l) (reduce-init + 0 l))
  6781.           (sum 1 2 3 4)
  6782.              == (reduce-init + 0 (1 2 3 4))
  6783.              == (+ (+ (+ (+ 0 1) 2) 3) 4)
  6784.              => 10
  6785.           (sum)
  6786.              == (reduce-init + 0 '())
  6787.              => 0
  6788.           
  6789.           (reduce-init string-append "@" '("hello" "cruel" "world"))
  6790.           ==
  6791.           (string-append (string-append (string-append "@" "hello")
  6792.                                          "cruel")
  6793.                          "world")
  6794.           => "@hellocruelworld"
  6795.      Given a differentiation of 2 arguments, `diff', the following will
  6796.      differentiate by any number of variables.
  6797.           (define (diff* exp . vars)
  6798.             (reduce-init diff exp vars))
  6799.      Example:
  6800.           ;;; Real-world example:  Insertion sort using reduce-init.
  6801.           
  6802.           (define (insert l item)
  6803.             (if (null? l)
  6804.                 (list item)
  6805.                 (if (< (car l) item)
  6806.                     (cons (car l) (insert (cdr l) item))
  6807.                     (cons item l))))
  6808.           (define (insertion-sort l) (reduce-init insert '() l))
  6809.           
  6810.           (insertion-sort '(3 1 4 1 5)
  6811.              == (reduce-init insert () (3 1 4 1 5))
  6812.              == (insert (insert (insert (insert (insert () 3) 1) 4) 1) 5)
  6813.              == (insert (insert (insert (insert (3)) 1) 4) 1) 5)
  6814.              == (insert (insert (insert (1 3) 4) 1) 5)
  6815.              == (insert (insert (1 3 4) 1) 5)
  6816.              == (insert (1 1 3 4) 5)
  6817.              => (1 1 3 4 5)
  6818.  - Function: last LST N
  6819.      `last' returns the last N elements of LST.  N must be a
  6820.      non-negative integer.
  6821.      Example:
  6822.           (last '(foo bar baz bang) 2)
  6823.              => (baz bang)
  6824.           (last '(1 2 3) 0)
  6825.              => 0
  6826.  - Function: butlast LST N
  6827.      `butlast' returns all but the last N elements of LST.
  6828.      Example:
  6829.           (butlast '(a b c d) 3)
  6830.              => (a)
  6831.           (butlast '(a b c d) 4)
  6832.              => ()
  6833. `last' and `butlast' split a list into two parts when given identical
  6834. arugments.
  6835.      (last '(a b c d e) 2)
  6836.         => (d e)
  6837.      (butlast '(a b c d e) 2)
  6838.         => (a b c)
  6839.  - Function: nthcdr N LST
  6840.      `nthcdr' takes N `cdr's of LST and returns the result.  Thus
  6841.      `(nthcdr 3 LST)' == `(cdddr LST)'
  6842.      Example:
  6843.           (nthcdr 2 '(a b c d))
  6844.              => (c d)
  6845.           (nthcdr 0 '(a b c d))
  6846.              => (a b c d)
  6847.  - Function: butnthcdr N LST
  6848.      `butnthcdr' returns all but the nthcdr N elements of LST.
  6849.      Example:
  6850.           (butnthcdr 3 '(a b c d))
  6851.              => (a b c)
  6852.           (butnthcdr 4 '(a b c d))
  6853.              => ()
  6854. `nthcdr' and `butnthcdr' split a list into two parts when given
  6855. identical arugments.
  6856.      (nthcdr 2 '(a b c d e))
  6857.         => (c d e)
  6858.      (butnthcdr 2 '(a b c d e))
  6859.         => (a b)
  6860. File: slib.info,  Node: Destructive list operations,  Next: Non-List functions,  Prev: Lists as sequences,  Up: Common List Functions
  6861. Destructive list operations
  6862. ...........................
  6863.   These procedures may mutate the list they operate on, but any such
  6864. mutation is undefined.
  6865.  - Procedure: nconc ARGS
  6866.      `nconc' destructively concatenates its arguments.  (Compare this
  6867.      with `append', which copies arguments rather than destroying them.)
  6868.      Sometimes called `append!' (*Note Rev2 Procedures::).
  6869.      Example:  You want to find the subsets of a set.  Here's the
  6870.      obvious way:
  6871.           (define (subsets set)
  6872.             (if (null? set)
  6873.                 '(())
  6874.                 (append (mapcar (lambda (sub) (cons (car set) sub))
  6875.                                 (subsets (cdr set)))
  6876.                         (subsets (cdr set)))))
  6877.      But that does way more consing than you need.  Instead, you could
  6878.      replace the `append' with `nconc', since you don't have any need
  6879.      for all the intermediate results.
  6880.      Example:
  6881.           (define x '(a b c))
  6882.           (define y '(d e f))
  6883.           (nconc x y)
  6884.              => (a b c d e f)
  6885.           x
  6886.              => (a b c d e f)
  6887.      `nconc' is the same as `append!' in `sc2.scm'.
  6888.  - Procedure: nreverse LST
  6889.      `nreverse' reverses the order of elements in LST by mutating
  6890.      `cdr's of the list.  Sometimes called `reverse!'.
  6891.      Example:
  6892.           (define foo '(a b c))
  6893.           (nreverse foo)
  6894.              => (c b a)
  6895.           foo
  6896.              => (a)
  6897.      Some people have been confused about how to use `nreverse',
  6898.      thinking that it doesn't return a value.  It needs to be pointed
  6899.      out that
  6900.           (set! lst (nreverse lst))
  6901.      is the proper usage, not
  6902.           (nreverse lst)
  6903.      The example should suffice to show why this is the case.
  6904.  - Procedure: delete ELT LST
  6905.  - Procedure: delete-if PRED LST
  6906.  - Procedure: delete-if-not PRED LST
  6907.      Destructive versions of `remove' `remove-if', and `remove-if-not'.
  6908.      Example:
  6909.           (define lst '(foo bar baz bang))
  6910.           (delete 'foo lst)
  6911.              => (bar baz bang)
  6912.           lst
  6913.              => (foo bar baz bang)
  6914.           
  6915.           (define lst '(1 2 3 4 5 6 7 8 9))
  6916.           (delete-if odd? lst)
  6917.              => (2 4 6 8)
  6918.           lst
  6919.              => (1 2 4 6 8)
  6920.      Some people have been confused about how to use `delete',
  6921.      `delete-if', and `delete-if', thinking that they dont' return a
  6922.      value.  It needs to be pointed out that
  6923.           (set! lst (delete el lst))
  6924.      is the proper usage, not
  6925.           (delete el lst)
  6926.      The examples should suffice to show why this is the case.
  6927. File: slib.info,  Node: Non-List functions,  Prev: Destructive list operations,  Up: Common List Functions
  6928. Non-List functions
  6929. ..................
  6930.  - Function: and? . ARGS
  6931.      `and?' checks to see if all its arguments are true.  If they are,
  6932.      `and?' returns `#t', otherwise, `#f'.  (In contrast to `and', this
  6933.      is a function, so all arguments are always evaluated and in an
  6934.      unspecified order.)
  6935.      Example:
  6936.           (and? 1 2 3)
  6937.              => #t
  6938.           (and #f 1 2)
  6939.              => #f
  6940.  - Function: or? . ARGS
  6941.      `or?' checks to see if any of its arguments are true.  If any is
  6942.      true, `or?' returns `#t', and `#f' otherwise.  (To `or' as `and?'
  6943.      is to `and'.)
  6944.      Example:
  6945.           (or? 1 2 #f)
  6946.              => #t
  6947.           (or? #f #f #f)
  6948.              => #f
  6949.  - Function: atom? OBJECT
  6950.      Returns `#t' if OBJECT is not a pair and `#f' if it is pair.
  6951.      (Called `atom' in Common LISP.)
  6952.           (atom? 1)
  6953.              => #t
  6954.           (atom? '(1 2))
  6955.              => #f
  6956.           (atom? #(1 2))   ; dubious!
  6957.              => #t
  6958.  - Function: type-of OBJECT
  6959.      Returns a symbol name for the type of OBJECT.
  6960.  - Function: coerce OBJECT RESULT-TYPE
  6961.      Converts and returns OBJECT of type `char', `number', `string',
  6962.      `symbol', `list', or `vector' to RESULT-TYPE (which must be one of
  6963.      these symbols).
  6964. File: slib.info,  Node: Tree Operations,  Next: Chapter Ordering,  Prev: Common List Functions,  Up: Procedures
  6965. Tree operations
  6966. ---------------
  6967.   `(require 'tree)'
  6968.   These are operations that treat lists a representations of trees.
  6969.  - Function: subst NEW OLD TREE
  6970.  - Function: substq NEW OLD TREE
  6971.  - Function: substv NEW OLD TREE
  6972.      `subst' makes a copy of TREE, substituting NEW for every subtree
  6973.      or leaf of TREE which is `equal?' to OLD and returns a modified
  6974.      tree.  The original TREE is unchanged, but may share parts with
  6975.      the result.
  6976.      `substq' and `substv' are similar, but test against OLD using
  6977.      `eq?' and `eqv?' respectively.
  6978.      Examples:
  6979.           (substq 'tempest 'hurricane '(shakespeare wrote (the hurricane)))
  6980.              => (shakespeare wrote (the tempest))
  6981.           (substq 'foo '() '(shakespeare wrote (twelfth night)))
  6982.              => (shakespeare wrote (twelfth night . foo) . foo)
  6983.           (subst '(a . cons) '(old . pair)
  6984.                  '((old . spice) ((old . shoes) old . pair) (old . pair)))
  6985.              => ((old . spice) ((old . shoes) a . cons) (a . cons))
  6986.  - Function: copy-tree TREE
  6987.      Makes a copy of the nested list structure TREE using new pairs and
  6988.      returns it.  All levels are copied, so that none of the pairs in
  6989.      the tree are `eq?' to the original ones - only the leaves are.
  6990.      Example:
  6991.           (define bar '(bar))
  6992.           (copy-tree (list bar 'foo))
  6993.              => ((bar) foo)
  6994.           (eq? bar (car (copy-tree (list bar 'foo))))
  6995.              => #f
  6996. File: slib.info,  Node: Chapter Ordering,  Next: Sorting,  Prev: Tree Operations,  Up: Procedures
  6997. Chapter Ordering
  6998. ----------------
  6999.   `(require 'chapter-order)'
  7000.   The `chap:' functions deal with strings which are ordered like
  7001. chapter numbers (or letters) in a book.  Each section of the string
  7002. consists of consecutive numeric or consecutive aphabetic characters of
  7003. like case.
  7004.  - Function: chap:string<? STRING1 STRING2
  7005.      Returns #t if the first non-matching run of alphabetic upper-case
  7006.      or the first non-matching run of alphabetic lower-case or the first
  7007.      non-matching run of numeric characters of STRING1 is `string<?'
  7008.      than the corresponding non-matching run of characters of STRING2.
  7009.           (chap:string<? "a.9" "a.10")                    => #t
  7010.           (chap:string<? "4c" "4aa")                      => #t
  7011.           (chap:string<? "Revised^{3.99}" "Revised^{4}")  => #t
  7012.  - Function: chap:string>? STRING1 STRING2
  7013.  - Function: chap:string<=? STRING1 STRING2
  7014.  - Function: chap:string>=? STRING1 STRING2
  7015.      Implement the corresponding chapter-order predicates.
  7016.  - Function: chap:next-string STRING
  7017.      Returns the next string in the *chapter order*.  If STRING has no
  7018.      alphabetic or numeric characters, `(string-append STRING "0")' is
  7019.      returnd.  The argument to chap:next-string will always be
  7020.      `chap:string<?' than the result.
  7021.           (chap:next-string "a.9")                => "a.10"
  7022.           (chap:next-string "4c")                 => "4d"
  7023.           (chap:next-string "4z")                 => "4aa"
  7024.           (chap:next-string "Revised^{4}")        => "Revised^{5}"
  7025. File: slib.info,  Node: Sorting,  Next: Topological Sort,  Prev: Chapter Ordering,  Up: Procedures
  7026. Sorting
  7027. -------
  7028.   `(require 'sort)'
  7029.   Many Scheme systems provide some kind of sorting functions.  They do
  7030. not, however, always provide the *same* sorting functions, and those
  7031. that I have had the opportunity to test provided inefficient ones (a
  7032. common blunder is to use quicksort which does not perform well).
  7033.   Because `sort' and `sort!' are not in the standard, there is very
  7034. little agreement about what these functions look like.  For example,
  7035. Dybvig says that Chez Scheme provides
  7036.      (merge predicate list1 list2)
  7037.      (merge! predicate list1 list2)
  7038.      (sort predicate list)
  7039.      (sort! predicate list)
  7040. while MIT Scheme 7.1, following Common LISP, offers unstable
  7041.      (sort list predicate)
  7042. TI PC Scheme offers
  7043.      (sort! list/vector predicate?)
  7044. and Elk offers
  7045.      (sort list/vector predicate?)
  7046.      (sort! list/vector predicate?)
  7047.   Here is a comprehensive catalogue of the variations I have found.
  7048.   1. Both `sort' and `sort!' may be provided.
  7049.   2. `sort' may be provided without `sort!'.
  7050.   3. `sort!' may be provided without `sort'.
  7051.   4. Neither may be provided.
  7052.   5. The sequence argument may be either a list or a vector.
  7053.   6. The sequence argument may only be a list.
  7054.   7. The sequence argument may only be a vector.
  7055.   8. The comparison function may be expected to behave like `<'.
  7056.   9. The comparison function may be expected to behave like `<='.
  7057.  10. The interface may be `(sort predicate? sequence)'.
  7058.  11. The interface may be `(sort sequence predicate?)'.
  7059.  12. The interface may be `(sort sequence &optional (predicate? <))'.
  7060.  13. The sort may be stable.
  7061.  14. The sort may be unstable.
  7062.   All of this variation really does not help anybody.  A nice simple
  7063. merge sort is both stable and fast (quite a lot faster than *quick*
  7064. sort).
  7065.   I am providing this source code with no restrictions at all on its use
  7066. (but please retain D.H.D.Warren's credit for the original idea).  You
  7067. may have to rename some of these functions in order to use them in a
  7068. system which already provides incompatible or inferior sorts.  For each
  7069. of the functions, only the top-level define needs to be edited to do
  7070. that.
  7071.   I could have given these functions names which would not clash with
  7072. any Scheme that I know of, but I would like to encourage implementors to
  7073. converge on a single interface, and this may serve as a hint.  The
  7074. argument order for all functions has been chosen to be as close to
  7075. Common LISP as made sense, in order to avoid NIH-itis.
  7076.   Each of the five functions has a required *last* parameter which is a
  7077. comparison function.  A comparison function `f' is a function of 2
  7078. arguments which acts like `<'.  For example,
  7079.      (not (f x x))
  7080.      (and (f x y) (f y z)) == (f x z)
  7081.   The standard functions `<', `>', `char<?', `char>?', `char-ci<?',
  7082. `char-ci>?', `string<?', `string>?', `string-ci<?', and `string-ci>?'
  7083. are suitable for use as comparison functions.  Think of `(less? x y)'
  7084. as saying when `x' must *not* precede `y'.
  7085.  - Function: sorted? SEQUENCE LESS?
  7086.      Returns `#t' when the sequence argument is in non-decreasing order
  7087.      according to LESS? (that is, there is no adjacent pair `... x y
  7088.      ...' for which `(less? y x)').
  7089.      Returns `#f' when the sequence contains at least one out-of-order
  7090.      pair.  It is an error if the sequence is neither a list nor a
  7091.      vector.
  7092.  - Function: merge LIST1 LIST2 LESS?
  7093.      This merges two lists, producing a completely new list as result.
  7094.      I gave serious consideration to producing a Common-LISP-compatible
  7095.      version.  However, Common LISP's `sort' is our `sort!' (well, in
  7096.      fact Common LISP's `stable-sort' is our `sort!', merge sort is
  7097.      *fast* as well as stable!) so adapting CL code to Scheme takes a
  7098.      bit of work anyway.  I did, however, appeal to CL to determine the
  7099.      *order* of the arguments.
  7100.  - Procedure: merge! LIST1 LIST2 LESS?
  7101.      Merges two lists, re-using the pairs of LIST1 and LIST2 to build
  7102.      the result.  If the code is compiled, and LESS? constructs no new
  7103.      pairs, no pairs at all will be allocated.  The first pair of the
  7104.      result will be either the first pair of LIST1 or the first pair of
  7105.      LIST2, but you can't predict which.
  7106.      The code of `merge' and `merge!' could have been quite a bit
  7107.      simpler, but they have been coded to reduce the amount of work
  7108.      done per iteration.  (For example, we only have one `null?' test
  7109.      per iteration.)
  7110.  - Function: sort SEQUENCE LESS?
  7111.      Accepts either a list or a vector, and returns a new sequence
  7112.      which is sorted.  The new sequence is the same type as the input.
  7113.      Always `(sorted? (sort sequence less?) less?)'.  The original
  7114.      sequence is not altered in any way.  The new sequence shares its
  7115.      *elements* with the old one; no elements are copied.
  7116.  - Procedure: sort! SEQUENCE LESS?
  7117.      Returns its sorted result in the original boxes.  If the original
  7118.      sequence is a list, no new storage is allocated at all.  If the
  7119.      original sequence is a vector, the sorted elements are put back in
  7120.      the same vector.
  7121.      Some people have been confused about how to use `sort!', thinking
  7122.      that it doesn't return a value.  It needs to be pointed out that
  7123.           (set! slist (sort! slist <))
  7124.      is the proper usage, not
  7125.           (sort! slist <)
  7126.   Note that these functions do *not* accept a CL-style `:key' argument.
  7127. A simple device for obtaining the same expressiveness is to define
  7128.      (define (keyed less? key)
  7129.        (lambda (x y) (less? (key x) (key y))))
  7130. and then, when you would have written
  7131.      (sort a-sequence #'my-less :key #'my-key)
  7132. in Common LISP, just write
  7133.      (sort! a-sequence (keyed my-less? my-key))
  7134. in Scheme.
  7135. File: slib.info,  Node: Topological Sort,  Next: String-Case,  Prev: Sorting,  Up: Procedures
  7136. Topological Sort
  7137. ----------------
  7138.   `(require 'topological-sort)' or `(require 'tsort)'
  7139. The algorithm is inspired by Cormen, Leiserson and Rivest (1990)
  7140. `Introduction to Algorithms', chapter 23.
  7141.  - Function: tsort DAG PRED
  7142.  - Function: topological-sort DAG PRED
  7143.      where
  7144.     DAG
  7145.           is a list of sublists.  The car of each sublist is a vertex.
  7146.           The cdr is the adjacency list of that vertex, i.e. a list of
  7147.           all vertices to which there exists an edge from the car
  7148.           vertex.
  7149.     PRED
  7150.           is one of `eq?', `eqv?', `equal?', `=', `char=?',
  7151.           `char-ci=?', `string=?', or `string-ci=?'.
  7152.      Sort the directed acyclic graph DAG so that for every edge from
  7153.      vertex U to V, U will come before V in the resulting list of
  7154.      vertices.
  7155.      Time complexity: O (|V| + |E|)
  7156.      Example (from Cormen):
  7157.           Prof. Bumstead topologically sorts his clothing when getting
  7158.           dressed.  The first argument to `tsort' describes which
  7159.           garments he needs to put on before others.  (For example,
  7160.           Prof Bumstead needs to put on his shirt before he puts on his
  7161.           tie or his belt.)  `tsort' gives the correct order of
  7162.           dressing:
  7163.           (require 'tsort)
  7164.           (tsort '((shirt tie belt)
  7165.                    (tie jacket)
  7166.                    (belt jacket)
  7167.                    (watch)
  7168.                    (pants shoes belt)
  7169.                    (undershorts pants shoes)
  7170.                    (socks shoes))
  7171.                  eq?)
  7172.           =>
  7173.           (socks undershorts pants shoes watch shirt belt tie jacket)
  7174. File: slib.info,  Node: String-Case,  Next: String Ports,  Prev: Topological Sort,  Up: Procedures
  7175. String-Case
  7176. -----------
  7177.   `(require 'string-case)'
  7178.  - Procedure: string-upcase STR
  7179.  - Procedure: string-downcase STR
  7180.  - Procedure: string-capitalize STR
  7181.      The obvious string conversion routines.  These are non-destructive.
  7182.  - Function: string-upcase! STR
  7183.  - Function: string-downcase! STR
  7184.  - Function: string-captialize! STR
  7185.      The destructive versions of the functions above.
  7186.  - Function: string-ci->symbol STR
  7187.      Converts string STR to a symbol having the same case as if the
  7188.      symbol had been `read'.
  7189. File: slib.info,  Node: String Ports,  Next: String Search,  Prev: String-Case,  Up: Procedures
  7190. String Ports
  7191. ------------
  7192.   `(require 'string-port)'
  7193.  - Procedure: call-with-output-string PROC
  7194.      PROC must be a procedure of one argument.  This procedure calls
  7195.      PROC with one argument: a (newly created) output port.  When the
  7196.      function returns, the string composed of the characters written
  7197.      into the port is returned.
  7198.  - Procedure: call-with-input-string STRING PROC
  7199.      PROC must be a procedure of one argument.  This procedure calls
  7200.      PROC with one argument: an (newly created) input port from which
  7201.      STRING's contents may be read.  When PROC returns, the port is
  7202.      closed and the value yielded by the procedure PROC is returned.
  7203. File: slib.info,  Node: String Search,  Next: Line I/O,  Prev: String Ports,  Up: Procedures
  7204. String Search
  7205. -------------
  7206.   `(require 'string-search)'
  7207.  - Procedure: string-index STRING CHAR
  7208.  - Procedure: string-index-ci STRING CHAR
  7209.      Returns the index of the first occurence of CHAR within STRING, or
  7210.      `#f' if the STRING does not contain a character CHAR.
  7211.  - Procedure: string-reverse-index STRING CHAR
  7212.  - Procedure: string-reverse-index-ci STRING CHAR
  7213.      Returns the index of the last occurence of CHAR within STRING, or
  7214.      `#f' if the STRING does not contain a character CHAR.
  7215.  - procedure: substring? PATTERN STRING
  7216.  - procedure: substring-ci? PATTERN STRING
  7217.      Searches STRING to see if some substring of STRING is equal to
  7218.      PATTERN.  `substring?' returns the index of the first character of
  7219.      the first substring of STRING that is equal to PATTERN; or `#f' if
  7220.      STRING does not contain PATTERN.
  7221.           (substring? "rat" "pirate") =>  2
  7222.           (substring? "rat" "outrage") =>  #f
  7223.           (substring? "" any-string) =>  0
  7224.  - Procedure: find-string-from-port? STR IN-PORT MAX-NO-CHARS
  7225.      Looks for a string STR within the first MAX-NO-CHARS chars of the
  7226.      input port IN-PORT.
  7227.  - Procedure: find-string-from-port? STR IN-PORT
  7228.      When called with two arguments, the search span is limited by the
  7229.      end of the input stream.
  7230.  - Procedure: find-string-from-port? STR IN-PORT CHAR
  7231.      Searches up to the first occurrence of character CHAR in STR.
  7232.  - Procedure: find-string-from-port? STR IN-PORT PROC
  7233.      Searches up to the first occurrence of the procedure PROC
  7234.      returning non-false when called with a character (from IN-PORT)
  7235.      argument.
  7236.      When the STR is found, `find-string-from-port?' returns the number
  7237.      of characters it has read from the port, and the port is set to
  7238.      read the first char after that (that is, after the STR) The
  7239.      function returns `#f' when the STR isn't found.
  7240.      `find-string-from-port?' reads the port *strictly* sequentially,
  7241.      and does not perform any buffering.  So `find-string-from-port?'
  7242.      can be used even if the IN-PORT is open to a pipe or other
  7243.      communication channel.
  7244.  - Function: string-subst TXT OLD1 NEW1 ...
  7245.      Returns a copy of string TXT with all occurrences of string OLD1
  7246.      in TXT replaced with NEW1, OLD2 replaced with NEW2 ....
  7247. File: slib.info,  Node: Line I/O,  Next: Multi-Processing,  Prev: String Search,  Up: Procedures
  7248. Line I/O
  7249. --------
  7250.   `(require 'line-i/o)'
  7251.  - Function: read-line READ-LINE                                              |
  7252.  - Function: read-line READ-LINE PORT                                         |
  7253.      Returns a string of the characters up to, but not including a
  7254.      newline or end of file, updating PORT to point to the character
  7255.      following the newline.  If no characters are available, an end of
  7256.      file object is returned.  The PORT argument may be omitted, in           |
  7257.      which case it defaults to the value returned by                          |
  7258.      `current-input-port'.                                                    |
  7259.  - Function: read-line! READ-LINE! STRING                                     |
  7260.  - Function: read-line! READ-LINE! STRING PORT                                |
  7261.      Fills READ-LINE! with characters up to, but not including a              |
  7262.      newline or end of file, updating the PORT to point to the last           |
  7263.      character read or following the newline if it was read.  If no           |
  7264.      characters are available, an end of file object is returned.  If a       |
  7265.      newline or end of file was found, the number of characters read is       |
  7266.      returned.  Otherwise, `#f' is returned.  The PORT argument may be        |
  7267.      omitted, in which case it defaults to the value returned by              |
  7268.      `current-input-port'.                                                    |
  7269.                                                                               |
  7270.  - Function: write-line WRITE-LINE STRING                                     |
  7271.  - Function: write-line WRITE-LINE STRING PORT                                |
  7272.      Writes WRITE-LINE followed by a newline to the given PORT and            |
  7273.      returns an unspecified value.  The PORT argument may be omited, in       |
  7274.      which case it defaults to the value returned by                          |
  7275.      `current-input-port'.                                                    |
  7276.                                                                               |
  7277.  - Function: display-file PATH                                                |
  7278.  - Function: display-file PATH PORT                                           |
  7279.      Displays the contents of the file named by PATH to PORT.  The PORT       |
  7280.      argument may be ommited, in which case it defaults to the value          |
  7281.      returned by `current-output-port'.                                       |
  7282. File: slib.info,  Node: Multi-Processing,  Prev: Line I/O,  Up: Procedures
  7283. Multi-Processing
  7284. ----------------
  7285.   `(require 'process)'
  7286.   This module implements asynchronous (non-polled) time-sliced
  7287. multi-processing in the SCM Scheme implementation using procedures
  7288. `alarm' and `alarm-interrupt'.  Until this is ported to another
  7289. implementation, consider it an example of writing schedulers in Scheme.
  7290.  - Procedure: add-process! PROC
  7291.      Adds proc, which must be a procedure (or continuation) capable of
  7292.      accepting accepting one argument, to the `process:queue'.  The
  7293.      value returned is unspecified.  The argument to PROC should be
  7294.      ignored.  If PROC returns, the process is killed.
  7295.  - Procedure: process:schedule!
  7296.      Saves the current process on `process:queue' and runs the next
  7297.      process from `process:queue'.  The value returned is unspecified.
  7298.  - Procedure: kill-process!
  7299.      Kills the current process and runs the next process from
  7300.      `process:queue'.  If there are no more processes on
  7301.      `process:queue', `(slib:exit)' is called (*Note System::).
  7302. File: slib.info,  Node: Standards Support,  Next: Session Support,  Prev: Procedures,  Up: Other Packages
  7303. Standards Support
  7304. =================
  7305. * Menu:
  7306. * With-File::                   'with-file
  7307. * Transcripts::                 'transcript
  7308. * Rev2 Procedures::             'rev2-procedures
  7309. * Rev4 Optional Procedures::    'rev4-optional-procedures
  7310. * Multi-argument / and -::      'multiarg/and-
  7311. * Multi-argument Apply::        'multiarg-apply
  7312. * Rationalize::                 'rationalize
  7313. * Promises::                    'promise
  7314. * Dynamic-Wind::                'dynamic-wind
  7315. * Eval::                        'eval
  7316. * Values::                      'values
  7317. File: slib.info,  Node: With-File,  Next: Transcripts,  Prev: Standards Support,  Up: Standards Support
  7318. With-File
  7319. ---------
  7320.   `(require 'with-file)'
  7321.  - Function: with-input-from-file FILE THUNK
  7322.  - Function: with-output-to-file FILE THUNK
  7323.      Description found in R4RS.
  7324. File: slib.info,  Node: Transcripts,  Next: Rev2 Procedures,  Prev: With-File,  Up: Standards Support
  7325. Transcripts
  7326. -----------
  7327.   `(require 'transcript)'
  7328.  - Function: transcript-on FILENAME
  7329.  - Function: transcript-off FILENAME
  7330.      Redefines `read-char', `read', `write-char', `write', `display',
  7331.      and `newline'.
  7332. File: slib.info,  Node: Rev2 Procedures,  Next: Rev4 Optional Procedures,  Prev: Transcripts,  Up: Standards Support
  7333. Rev2 Procedures
  7334. ---------------
  7335.   `(require 'rev2-procedures)'
  7336.   The procedures below were specified in the `Revised^2 Report on
  7337. Scheme'.  *N.B.*: The symbols `1+' and `-1+' are not `R4RS' syntax.
  7338. Scheme->C, for instance, barfs on this module.
  7339.  - Procedure: substring-move-left! STRING1 START1 END1 STRING2 START2
  7340.  - Procedure: substring-move-right! STRING1 START1 END1 STRING2 START2
  7341.      STRING1 and STRING2 must be a strings, and START1, START2 and END1
  7342.      must be exact integers satisfying
  7343.           0 <= START1 <= END1 <= (string-length STRING1)
  7344.           0 <= START2 <= END1 - START1 + START2 <= (string-length STRING2)
  7345.      `substring-move-left!' and `substring-move-right!' store
  7346.      characters of STRING1 beginning with index START1 (inclusive) and
  7347.      ending with index END1 (exclusive) into STRING2 beginning with
  7348.      index START2 (inclusive).
  7349.      `substring-move-left!' stores characters in time order of
  7350.      increasing indices.  `substring-move-right!' stores characters in
  7351.      time order of increasing indeces.
  7352.  - Procedure: substring-fill! STRING START END CHAR
  7353.      Fills the elements START-END of STRING with the character CHAR.
  7354.  - Function: string-null? STR
  7355.      == `(= 0 (string-length STR))'
  7356.  - Procedure: append! . PAIRS
  7357.      Destructively appends its arguments.  Equivalent to `nconc'.
  7358.  - Function: 1+ N
  7359.      Adds 1 to N.
  7360.  - Function: -1+ N
  7361.      Subtracts 1 from N.
  7362.  - Function: <?
  7363.  - Function: <=?
  7364.  - Function: =?
  7365.  - Function: >?
  7366.  - Function: >=?
  7367.      These are equivalent to the procedures of the same name but
  7368.      without the trailing `?'.
  7369. File: slib.info,  Node: Rev4 Optional Procedures,  Next: Multi-argument / and -,  Prev: Rev2 Procedures,  Up: Standards Support
  7370. Rev4 Optional Procedures
  7371. ------------------------
  7372.   `(require 'rev4-optional-procedures)'
  7373.   For the specification of these optional procedures, *Note Standard
  7374. procedures: (r4rs)Standard procedures.
  7375.  - Function: list-tail L P
  7376.  - Function: string->list S
  7377.  - Function: list->string L
  7378.  - Function: string-copy
  7379.  - Procedure: string-fill! S OBJ
  7380.  - Function: list->vector L
  7381.  - Function: vector->list S
  7382.  - Procedure: vector-fill! S OBJ
  7383. File: slib.info,  Node: Multi-argument / and -,  Next: Multi-argument Apply,  Prev: Rev4 Optional Procedures,  Up: Standards Support
  7384. Multi-argument / and -
  7385. ----------------------
  7386.   `(require 'mutliarg/and-)'
  7387.   For the specification of these optional forms, *Note Numerical
  7388. operations: (r4rs)Numerical operations.  The `two-arg:'* forms are only
  7389. defined if the implementation does not support the many-argument forms.
  7390.  - Function: two-arg:/ N1 N2
  7391.      The original two-argument version of `/'.
  7392.  - Function: / DIVIDENT . DIVISORS
  7393.  - Function: two-arg:- N1 N2
  7394.      The original two-argument version of `-'.
  7395.  - Function: - MINUEND . SUBTRAHENDS
  7396. File: slib.info,  Node: Multi-argument Apply,  Next: Rationalize,  Prev: Multi-argument / and -,  Up: Standards Support
  7397. Multi-argument Apply
  7398. --------------------
  7399.   `(require 'multiarg-apply)'
  7400. For the specification of this optional form, *Note Control features:
  7401. (r4rs)Control features.
  7402.  - Function: two-arg:apply PROC L
  7403.      The implementation's native `apply'.  Only defined for
  7404.      implementations which don't support the many-argument version.
  7405.  - Function: apply PROC . ARGS
  7406. File: slib.info,  Node: Rationalize,  Next: Promises,  Prev: Multi-argument Apply,  Up: Standards Support
  7407. Rationalize
  7408. -----------
  7409.   `(require 'rationalize)'
  7410.   The procedure rationalize is interesting because most programming
  7411. languages do not provide anything analogous to it.  For simplicity, we
  7412. present an algorithm which computes the correct result for exact
  7413. arguments (provided the implementation supports exact rational numbers
  7414. of unlimited precision), and produces a reasonable answer for inexact
  7415. arguments when inexact arithmetic is implemented using floating-point.
  7416. We thank Alan Bawden for contributing this algorithm.
  7417.  - Function: rationalize X E
  7418. File: slib.info,  Node: Promises,  Next: Dynamic-Wind,  Prev: Rationalize,  Up: Standards Support
  7419. Promises
  7420. --------
  7421.   `(require 'promise)'
  7422.  - Function: make-promise PROC
  7423.   Change occurrences of `(delay EXPRESSION)' to `(make-promise (lambda
  7424. () EXPRESSION))' and `(define force promise:force)' to implement
  7425. promises if your implementation doesn't support them (*note Control
  7426. features: (r4rs)Control features.).
  7427. File: slib.info,  Node: Dynamic-Wind,  Next: Eval,  Prev: Promises,  Up: Standards Support
  7428. Dynamic-Wind
  7429. ------------
  7430.   `(require 'dynamic-wind)'
  7431.   This facility is a generalization of Common LISP `unwind-protect',
  7432. designed to take into account the fact that continuations produced by
  7433. `call-with-current-continuation' may be reentered.
  7434.  - Procedure: dynamic-wind THUNK1 THUNK2 THUNK3
  7435.      The arguments THUNK1, THUNK2, and THUNK3 must all be procedures of
  7436.      no arguments (thunks).
  7437.      `dynamic-wind' calls THUNK1, THUNK2, and then THUNK3.  The value
  7438.      returned by THUNK2 is returned as the result of `dynamic-wind'.
  7439.      THUNK3 is also called just before control leaves the dynamic
  7440.      context of THUNK2 by calling a continuation created outside that
  7441.      context.  Furthermore, THUNK1 is called before reentering the
  7442.      dynamic context of THUNK2 by calling a continuation created inside
  7443.      that context.  (Control is inside the context of THUNK2 if THUNK2
  7444.      is on the current return stack).
  7445.      *Warning:* There is no provision for dealing with errors or
  7446.      interrupts.  If an error or interrupt occurs while using
  7447.      `dynamic-wind', the dynamic environment will be that in effect at
  7448.      the time of the error or interrupt.
  7449. File: slib.info,  Node: Eval,  Next: Values,  Prev: Dynamic-Wind,  Up: Standards Support
  7450.   `(require 'eval)'
  7451.  - Function: eval EXPRESSION ENVIRONMENT-SPECIFIER
  7452.      Evaluates EXPRESSION in the specified environment and returns its
  7453.      value.  EXPRESSION must be a valid Scheme expression represented
  7454.      as data, and ENVIRONMENT-SPECIFIER must be a value returned by one
  7455.      of the three procedures described below.  Implementations may
  7456.      extend `eval' to allow non-expression programs (definitions) as
  7457.      the first argument and to allow other values as environments, with
  7458.      the restriction that `eval' is not allowed to create new bindings
  7459.      in the environments associated with `null-environment' or
  7460.      `scheme-report-environment'.
  7461.           (eval '(* 7 3) (scheme-report-environment 5))
  7462.                                                              =>  21
  7463.           
  7464.           (let ((f (eval '(lambda (f x) (f x x))
  7465.                          (null-environment))))
  7466.             (f + 10))
  7467.                                                              =>  20
  7468.  - Function: scheme-report-environment VERSION
  7469.  - Function: null-environment VERSION
  7470.  - Function: null-environment
  7471.      VERSION must be an exact non-negative integer N corresponding to a
  7472.      version of one of the Revised^N Reports on Scheme.
  7473.      `Scheme-report-environment' returns a specifier for an environment
  7474.      that contains the set of bindings specified in the corresponding
  7475.      report that the implementation supports.  `Null-environment'
  7476.      returns a specifier for an environment that contains only the
  7477.      (syntactic) bindings for all the syntactic keywords defined in the
  7478.      given version of the report.
  7479.      Not all versions may be available in all implementations at all
  7480.      times.  However, an implementation that conforms to version N of
  7481.      the Revised^N Reports on Scheme must accept version N.  An error
  7482.      is signalled if the specified version is not available.
  7483.      The effect of assigning (through the use of `eval') a variable
  7484.      bound in a `scheme-report-environment' (for example `car') is
  7485.      unspecified. Thus the environments specified by
  7486.      `scheme-report-environment' may be immutable.
  7487.  - Function: interaction-environment
  7488.      This optional procedure returns a specifier for the environment
  7489.      that contains implementation-defined bindings, typically a
  7490.      superset of those listed in the report.  The intent is that this
  7491.      procedure will return the environment in which the implementation
  7492.      would evaluate expressions dynamically typed by the user.
  7493. Here are some more `eval' examples:
  7494.      (require 'eval)
  7495.      => #<unspecified>
  7496.      (define car 'volvo)
  7497.      => #<unspecified>
  7498.      car
  7499.      => volvo
  7500.      (eval 'car (interaction-environment))
  7501.      => volvo
  7502.      (eval 'car (scheme-report-environment 5))
  7503.      => #<primitive-procedure car>
  7504.      (eval '(eval 'car (interaction-environment))
  7505.            (scheme-report-environment 5))
  7506.      => volvo
  7507.      (eval '(eval '(set! car 'buick) (interaction-environment))
  7508.            (scheme-report-environment 5))
  7509.      => #<unspecified>
  7510.      car
  7511.      => buick
  7512.      (eval 'car (scheme-report-environment 5))
  7513.      => #<primitive-procedure car>
  7514.      (eval '(eval 'car (interaction-environment))
  7515.            (scheme-report-environment 5))
  7516.      => buick
  7517. File: slib.info,  Node: Values,  Prev: Eval,  Up: Standards Support
  7518. Values
  7519. ------
  7520.   `(require 'values)'
  7521.  - Function: values OBJ ...
  7522.      `values' takes any number of arguments, and passes (returns) them
  7523.      to its continuation.
  7524.  - Function: call-with-values THUNK PROC
  7525.      THUNK must be a procedure of no arguments, and PROC must be a
  7526.      procedure.  `call-with-values' calls THUNK with a continuation
  7527.      that, when passed some values, calls PROC with those values as
  7528.      arguments.
  7529.      Except for continuations created by the `call-with-values'
  7530.      procedure, all continuations take exactly one value, as now; the
  7531.      effect of passing no value or more than one value to continuations
  7532.      that were not created by the `call-with-values' procedure is
  7533.      unspecified.
  7534. File: slib.info,  Node: Session Support,  Next: Extra-SLIB Packages,  Prev: Standards Support,  Up: Other Packages
  7535. Session Support
  7536. ===============
  7537. * Menu:
  7538. * Repl::                        Macros at top-level
  7539. * Quick Print::                 Loop-safe Output
  7540. * Debug::                       To err is human ...
  7541. * Breakpoints::                 Pause execution
  7542. * Trace::                       'trace
  7543. * System Interface::            'system, 'getenv, and 'net-clients            |
  7544. File: slib.info,  Node: Repl,  Next: Quick Print,  Prev: Session Support,  Up: Session Support
  7545.   `(require 'repl)'
  7546.   Here is a read-eval-print-loop which, given an eval, evaluates forms.
  7547.  - Procedure: repl:top-level REPL:EVAL
  7548.      `read's, `repl:eval's and `write's expressions from
  7549.      `(current-input-port)' to `(current-output-port)' until an
  7550.      end-of-file is encountered.  `load', `slib:eval', `slib:error',
  7551.      and `repl:quit' dynamically bound during `repl:top-level'.
  7552.  - Procedure: repl:quit
  7553.      Exits from the invocation of `repl:top-level'.
  7554.   The `repl:' procedures establish, as much as is possible to do
  7555. portably, a top level environment supporting macros.  `repl:top-level'
  7556. uses `dynamic-wind' to catch error conditions and interrupts.  If your
  7557. implementation supports this you are all set.
  7558.   Otherwise, if there is some way your implementation can catch error
  7559. conditions and interrupts, then have them call `slib:error'.  It will
  7560. display its arguments and reenter `repl:top-level'.  `slib:error'
  7561. dynamically bound by `repl:top-level'.
  7562.   To have your top level loop always use macros, add any interrupt
  7563. catching lines and the following lines to your Scheme init file:
  7564.      (require 'macro)
  7565.      (require 'repl)
  7566.      (repl:top-level macro:eval)
  7567. File: slib.info,  Node: Quick Print,  Next: Debug,  Prev: Repl,  Up: Session Support
  7568. Quick Print
  7569. -----------
  7570.   `(require 'qp)'
  7571. When displaying error messages and warnings, it is paramount that the
  7572. output generated for circular lists and large data structures be
  7573. limited.  This section supplies a procedure to do this.  It could be
  7574. much improved.
  7575.      Notice that the neccessity for truncating output eliminates
  7576.      Common-Lisp's *Note Format:: from consideration; even when
  7577.      variables `*print-level*' and `*print-level*' are set, huge
  7578.      strings and bit-vectors are *not* limited.
  7579.  - Procedure: qp ARG1 ...
  7580.  - Procedure: qpn ARG1 ...
  7581.  - Procedure: qpr ARG1 ...
  7582.      `qp' writes its arguments, separated by spaces, to
  7583.      `(current-output-port)'.  `qp' compresses printing by substituting
  7584.      `...' for substructure it does not have sufficient room to print.
  7585.      `qpn' is like `qp' but outputs a newline before returning.  `qpr'
  7586.      is like `qpn' except that it returns its last argument.
  7587.  - Variable: *qp-width*
  7588.      `*qp-width*' is the largest number of characters that `qp' should
  7589.      use.
  7590. File: slib.info,  Node: Debug,  Next: Breakpoints,  Prev: Quick Print,  Up: Session Support
  7591. Debug
  7592. -----
  7593.   `(require 'debug)'
  7594. Requiring `debug' automatically requires `trace' and `break'.
  7595. An application with its own datatypes may want to substitute its own
  7596. printer for `qp'.  This example shows how to do this:
  7597.      (define qpn (lambda args) ...)
  7598.      (provide 'qp)
  7599.      (require 'debug)
  7600.  - Procedure: trace-all FILE
  7601.      Traces (*note Trace::.) all procedures `define'd at top-level in
  7602.      file `file'.
  7603.  - Procedure: break-all FILE
  7604.      Breakpoints (*note Breakpoints::.) all procedures `define'd at
  7605.      top-level in file `file'.
  7606. File: slib.info,  Node: Breakpoints,  Next: Trace,  Prev: Debug,  Up: Session Support
  7607. Breakpoints
  7608. -----------
  7609.   `(require 'break)'
  7610.  - Function: init-debug
  7611.      If your Scheme implementation does not support `break' or `abort',
  7612.      a message will appear when you `(require 'break)' or `(require
  7613.      'debug)' telling you to type `(init-debug)'.  This is in order to
  7614.      establish a top-level continuation.  Typing `(init-debug)' at top
  7615.      level sets up a continuation for `break'.
  7616.  - Function: breakpoint ARG1 ...
  7617.      Returns from the top level continuation and pushes the
  7618.      continuation from which it was called on a continuation stack.
  7619.  - Function: continue
  7620.      Pops the topmost continuation off of the continuation stack and
  7621.      returns an unspecified value to it.
  7622.  - Function: continue ARG1 ...
  7623.      Pops the topmost continuation off of the continuation stack and
  7624.      returns ARG1 ... to it.
  7625.  - Macro: break PROC1 ...
  7626.      Redefines the top-level named procedures given as arguments so that
  7627.      `breakpoint' is called before calling PROC1 ....
  7628.  - Macro: break
  7629.      With no arguments, makes sure that all the currently broken
  7630.      identifiers are broken (even if those identifiers have been
  7631.      redefined) and returns a list of the broken identifiers.
  7632.  - Macro: unbreak PROC1 ...
  7633.      Turns breakpoints off for its arguments.
  7634.  - Macro: unbreak
  7635.      With no arguments, unbreaks all currently broken identifiers and
  7636.      returns a list of these formerly broken identifiers.
  7637.   The following routines are the procedures which actually do the
  7638. tracing when this module is supplied by SLIB, rather than natively.  If
  7639. defmacros are not natively supported by your implementation, these might
  7640. be more convenient to use.
  7641.  - Function: breakf PROC
  7642.  - Function: breakf PROC NAME
  7643.  - Function: debug:breakf PROC
  7644.  - Function: debug:breakf PROC NAME
  7645.      To break, type
  7646.           (set! SYMBOL (breakf SYMBOL))
  7647.      or
  7648.           (set! SYMBOL (breakf SYMBOL 'SYMBOL))
  7649.      or
  7650.           (define SYMBOL (breakf FUNCTION))
  7651.      or
  7652.           (define SYMBOL (breakf FUNCTION 'SYMBOL))
  7653.  - Function: unbreakf PROC
  7654.  - Function: debug:unbreakf PROC
  7655.      To unbreak, type
  7656.           (set! SYMBOL (unbreakf SYMBOL))
  7657. File: slib.info,  Node: Trace,  Next: System Interface,  Prev: Breakpoints,  Up: Session Support
  7658. Tracing
  7659. -------
  7660.   `(require 'trace)'
  7661.  - Macro: trace PROC1 ...
  7662.      Traces the top-level named procedures given as arguments.
  7663.  - Macro: trace
  7664.      With no arguments, makes sure that all the currently traced
  7665.      identifiers are traced (even if those identifiers have been
  7666.      redefined) and returns a list of the traced identifiers.
  7667.  - Macro: untrace PROC1 ...
  7668.      Turns tracing off for its arguments.
  7669.  - Macro: untrace
  7670.      With no arguments, untraces all currently traced identifiers and
  7671.      returns a list of these formerly traced identifiers.
  7672.   The following routines are the procedures which actually do the
  7673. tracing when this module is supplied by SLIB, rather than natively.  If
  7674. defmacros are not natively supported by your implementation, these might
  7675. be more convenient to use.
  7676.  - Function: tracef PROC
  7677.  - Function: tracef PROC NAME
  7678.  - Function: debug:tracef PROC
  7679.  - Function: debug:tracef PROC NAME
  7680.      To trace, type
  7681.           (set! SYMBOL (tracef SYMBOL))
  7682.      or
  7683.           (set! SYMBOL (tracef SYMBOL 'SYMBOL))
  7684.      or
  7685.           (define SYMBOL (tracef FUNCTION))
  7686.      or
  7687.           (define SYMBOL (tracef FUNCTION 'SYMBOL))
  7688.  - Function: untracef PROC
  7689.  - Function: debug:untracef PROC
  7690.      To untrace, type
  7691.           (set! SYMBOL (untracef SYMBOL))
  7692. File: slib.info,  Node: System Interface,  Prev: Trace,  Up: Session Support
  7693.                                                                               |
  7694. System Interface
  7695. ----------------
  7696. If `(provided? 'getenv)':
  7697.  - Function: getenv NAME
  7698.      Looks up NAME, a string, in the program environment.  If NAME is
  7699.      found a string of its value is returned.  Otherwise, `#f' is
  7700.      returned.
  7701. If `(provided? 'system)':
  7702.  - Function: system COMMAND-STRING
  7703.      Executes the COMMAND-STRING on the computer and returns the
  7704.      integer status code.
  7705. If `system' is provided by the Scheme implementation, the "net-clients"       |
  7706. package provides interfaces to common network client programs like FTP,       |
  7707. mail, and Netscape.                                                           |
  7708.                                                                               |
  7709.   `(require 'net-clients)'                                                    |
  7710.                                                                               |
  7711.  - Function: call-with-tmpnam PROC                                            |
  7712.  - Function: call-with-tmpnam PROC K                                          |
  7713.      Calls PROC with K arguments, strings returned by successive calls        |
  7714.      to `tmpnam'.  If PROC returns, then any files named by the               |
  7715.      arguments to PROC are deleted automatically and the value(s)             |
  7716.      yielded by the PROC is(are) returned.  K may be ommited, in which        |
  7717.      case it defaults to `1'.                                                 |
  7718.                                                                               |
  7719.  - Function: user-email-address                                               |
  7720.      `user-email-address' returns a string of the form                        |
  7721.      `username@hostname'.  If this e-mail address cannot be obtained,         |
  7722.      #f is returned.                                                          |
  7723.                                                                               |
  7724.  - Function: current-directory                                                |
  7725.      `current-directory' returns a string containing the absolute file        |
  7726.      name representing the current working directory.  If this string         |
  7727.      cannot be obtained, #f is returned.                                      |
  7728.                                                                               |
  7729.      If `current-directory' cannot be supported by the platform, the          |
  7730.      value of `current-directory' is #f.                                      |
  7731.                                                                               |
  7732.  - Function: make-directory NAME                                              |
  7733.      Creates a sub-directory NAME of the current-directory.  If               |
  7734.      successful, `make-directory' returns #t; otherwise #f.                   |
  7735.                                                                               |
  7736.  - Function: null-directory? FILE-NAME                                        |
  7737.      Returns #t if changing directory to FILE-NAME makes the current          |
  7738.      working directory the same as it is before changing directory;           |
  7739.      otherwise returns #f.                                                    |
  7740.                                                                               |
  7741.  - Function: absolute-path? FILE-NAME                                         |
  7742.      Returns #t if FILE-NAME is a fully specified pathname (does not          |
  7743.      depend on the current working directory); otherwise returns #f.          |
  7744.                                                                               |
  7745.  - Function: glob-pattern? STR                                                |
  7746.      Returns #t if the string STR contains characters used for                |
  7747.      specifying glob patterns, namely `*', `?', or `['.                       |
  7748.                                                                               |
  7749.  - Function: parse-ftp-address URL                                            |
  7750.      Returns a list of the decoded FTP URL; or #f if indecipherable.          |
  7751.      FTP "Uniform Resource Locator", "ange-ftp", and "getit" formats          |
  7752.      are handled.  The returned list has four elements which are              |
  7753.      strings or #f:                                                           |
  7754.                                                                               |
  7755.        0. username                                                            |
  7756.                                                                               |
  7757.        1. password                                                            |
  7758.                                                                               |
  7759.        2. remote-site                                                         |
  7760.                                                                               |
  7761.        3. remote-directory                                                    |
  7762.                                                                               |
  7763.  - Function: ftp-upload PATHS USER PASSWORD REMOTE-SITE REMOTE-DIR            |
  7764.      PASSWORD must be a non-empty string or #f.  PATHS must be a              |
  7765.      non-empty list of pathnames or Glob patterns (*note Filenames::.)        |
  7766.      matching files to transfer.                                              |
  7767.                                                                               |
  7768.      `ftp-upload' puts the files specified by PATHS into the REMOTE-DIR       |
  7769.      directory of FTP REMOTE-SITE using name USER with (optional)             |
  7770.      PASSWORD.                                                                |
  7771.                                                                               |
  7772.      If PASSWORD is #f and USER is not `ftp' or `anonymous', then USER        |
  7773.      is ignored; FTP takes the username and password from the `.netrc'        |
  7774.      or equivalent file.                                                      |
  7775.                                                                               |
  7776.  - Function: path->url PATH                                                   |
  7777.      Returns a URL-string for PATH on the local host.                         |
  7778.                                                                               |
  7779.  - Function: browse-url-netscape URL                                          |
  7780.      If a `netscape' browser is running, `browse-url-netscape' causes         |
  7781.      the browser to display the page specified by string URL and              |
  7782.      returns #t.                                                              |
  7783.                                                                               |
  7784.      If the browser is not running, `browse-url-netscape' runs                |
  7785.      `netscape' with the argument URL.  If the browser starts,                |
  7786.      `browse-url-netscape' returns #t when the browser exits; otherwise       |
  7787.      it returns #f.                                                           |
  7788. File: slib.info,  Node: Extra-SLIB Packages,  Prev: Session Support,  Up: Other Packages
  7789. Extra-SLIB Packages
  7790. ===================
  7791.   Several Scheme packages have been written using SLIB.  There are
  7792. several reasons why a package might not be included in the SLIB
  7793. distribution:
  7794.    * Because it requires special hardware or software which is not
  7795.      universal.
  7796.    * Because it is large and of limited interest to most Scheme users.
  7797.    * Because it has copying terms different enough from the other SLIB
  7798.      packages that its inclusion would cause confusion.
  7799.    * Because it is an application program, rather than a library module.
  7800.    * Because I have been too busy to integrate it.
  7801.   Once an optional package is installed (and an entry added to
  7802. `*catalog*', the `require' mechanism allows it to be called up and used
  7803. as easily as any other SLIB package.  Some optional packages (for which
  7804. `*catalog*' already has entries) available from SLIB sites are:
  7805. SLIB-PSD is a portable debugger for Scheme (requires emacs editor).
  7806.           swissnet.ai.mit.edu:pub/scm/slib-psd1-3.tar.gz
  7807.           ftp.gnu.org:pub/gnu/jacal/slib-psd1-3.tar.gz                        |
  7808.           ftp.maths.tcd.ie:pub/bosullvn/jacal/slib-psd1-3.tar.gz
  7809.           ftp.cs.indiana.edu:/pub/scheme-repository/utl/slib-psd1-3.tar.gz
  7810.      With PSD, you can run a Scheme program in an Emacs buffer, set
  7811.      breakpoints, single step evaluation and access and modify the
  7812.      program's variables. It works by instrumenting the original source
  7813.      code, so it should run with any R4RS compliant Scheme. It has been
  7814.      tested with SCM, Elk 1.5, and the sci interpreter in the Scheme->C
  7815.      system, but should work with other Schemes with a minimal amount
  7816.      of porting, if at all. Includes documentation and user's manual.
  7817.      Written by Pertti Kellom\"aki, pk@cs.tut.fi.  The Lisp Pointers
  7818.      article describing PSD (Lisp Pointers VI(1):15-23, January-March
  7819.      1993) is available as
  7820.      `http://www.cs.tut.fi/staff/pk/scheme/psd/article/article.html'
  7821. SCHELOG is an embedding of Prolog in Scheme.
  7822.      `http://www.cs.rice.edu/CS/PLT/packages/schelog/'
  7823. File: slib.info,  Node: About SLIB,  Next: Index,  Prev: Other Packages,  Up: Top
  7824. About SLIB
  7825. **********
  7826. * Menu:
  7827. * Installation::                How to install SLIB on your system.
  7828. * Porting::                     SLIB to new platforms.
  7829. * Coding Standards::            How to write modules for SLIB.
  7830. * Copyrights::                  Intellectual propery issues.
  7831. More people than I can name have contributed to SLIB.  Thanks to all of
  7832. File: slib.info,  Node: Installation,  Next: Porting,  Prev: About SLIB,  Up: About SLIB
  7833. Installation
  7834. ============
  7835.   Check the manifest in `README' to find a configuration file for your
  7836. Scheme implementation.  Initialization files for most IEEE P1178
  7837. compliant Scheme Implementations are included with this distribution.
  7838.   If the Scheme implementation supports `getenv', then the value of the
  7839. shell environment variable SCHEME_LIBRARY_PATH will be used for
  7840. `(library-vicinity)' if it is defined.  Currently, Chez, Elk,
  7841. MITScheme, scheme->c, VSCM, and SCM support `getenv'.  Scheme48
  7842. supports `getenv' but does not use it for determining
  7843. `library-vicinity'.  (That is done from the Makefile.)
  7844.   You should check the definitions of `software-type',
  7845. `scheme-implementation-version', `implementation-vicinity', and
  7846. `library-vicinity' in the initialization file.  There are comments in
  7847. the file for how to configure it.
  7848.   Once this is done you can modify the startup file for your Scheme
  7849. implementation to `load' this initialization file.  SLIB is then
  7850. installed.
  7851.   Multiple implementations of Scheme can all use the same SLIB
  7852. directory.  Simply configure each implementation's initialization file
  7853. as outlined above.
  7854.   The SCM implementation does not require any initialization file as
  7855. SLIB support is already built in to SCM.  See the documentation with
  7856. SCM for installation instructions.
  7857.   SLIB includes methods to create heap images for the VSCM and Scheme48
  7858. implementations.  The instructions for creating a VSCM image are in
  7859. comments in `vscm.init'.  To make a Scheme48 image for an installation
  7860. under `<prefix>', `cd' to the SLIB directory and type `make
  7861. prefix=<prefix> slib48'.  To install the image, type `make
  7862. prefix=<prefix> install48'.  This will also create a shell script with
  7863. the name `slib48' which will invoke the saved image.
  7864. File: slib.info,  Node: Porting,  Next: Coding Standards,  Prev: Installation,  Up: About SLIB
  7865. Porting
  7866. =======
  7867.   If there is no initialization file for your Scheme implementation, you
  7868. will have to create one.  Your Scheme implementation must be largely
  7869. compliant with `IEEE Std 1178-1990', `Revised^4 Report on the
  7870. Algorithmic Language Scheme', or `Revised^5 Report on the Algorithmic
  7871. Language Scheme' in order to support SLIB.  (1)
  7872.   `Template.scm' is an example configuration file.  The comments inside
  7873. will direct you on how to customize it to reflect your system.  Give
  7874. your new initialization file the implementation's name with `.init'
  7875. appended.  For instance, if you were porting `foo-scheme' then the
  7876. initialization file might be called `foo.init'.
  7877.   Your customized version should then be loaded as part of your scheme
  7878. implementation's initialization.  It will load `require.scm' from the
  7879. library; this will allow the use of `provide', `provided?', and
  7880. `require' along with the "vicinity" functions (these functions are
  7881. documented in the section *Note Require::).  The rest of the library
  7882. will then be accessible in a system independent fashion.
  7883.   Please mail new working configuration files to `jaffer @ ai.mit.edu'        |
  7884. so that they can be included in the SLIB distribution.                        |
  7885.   ---------- Footnotes ----------
  7886.   (1) If you are porting a `Revised^3 Report on the Algorithmic
  7887. Language Scheme' implementation, then you will need to finish writing
  7888. `sc4sc3.scm' and `load' it from your initialization file.
  7889. File: slib.info,  Node: Coding Standards,  Next: Copyrights,  Prev: Porting,  Up: About SLIB
  7890. Coding Standards
  7891. ================
  7892.   All library packages are written in IEEE P1178 Scheme and assume that
  7893. a configuration file and `require.scm' package have already been
  7894. loaded.  Other versions of Scheme can be supported in library packages
  7895. as well by using, for example, `(provided? 'rev3-report)' or `(require
  7896. 'rev3-report)' (*Note Require::).
  7897.   The module name and `:' should prefix each symbol defined in the
  7898. package.  Definitions for external use should then be exported by having
  7899. `(define foo module-name:foo)'.
  7900.   Code submitted for inclusion in SLIB should not duplicate routines
  7901. already in SLIB files.  Use `require' to force those library routines
  7902. to be used by your package.  Care should be taken that there are no
  7903. circularities in the `require's and `load's between the library
  7904. packages.
  7905.   Documentation should be provided in Emacs Texinfo format if possible,
  7906. But documentation must be provided.
  7907.   Your package will be released sooner with SLIB if you send me a file
  7908. which tests your code.  Please run this test *before* you send me the
  7909. code!
  7910. Modifications
  7911. -------------
  7912.   Please document your changes.  A line or two for `ChangeLog' is
  7913. sufficient for simple fixes or extensions.  Look at the format of
  7914. `ChangeLog' to see what information is desired.  Please send me `diff'
  7915. files from the latest SLIB distribution (remember to send `diff's of
  7916. `slib.texi' and `ChangeLog').  This makes for less email traffic and
  7917. makes it easier for me to integrate when more than one person is
  7918. changing a file (this happens a lot with `slib.texi' and `*.init'
  7919. files).
  7920.   If someone else wrote a package you want to significantly modify,
  7921. please try to contact the author, who may be working on a new version.
  7922. This will insure against wasting effort on obsolete versions.
  7923.   Please *do not* reformat the source code with your favorite
  7924. beautifier, make 10 fixes, and send me the resulting source code.  I do
  7925. not have the time to fish through 10000 diffs to find your 10 real
  7926. fixes.
  7927. File: slib.info,  Node: Copyrights,  Prev: Coding Standards,  Up: About SLIB
  7928. Copyrights
  7929. ==========
  7930.   This section has instructions for SLIB authors regarding copyrights.
  7931.   Each package in SLIB must either be in the public domain, or come
  7932. with a statement of terms permitting users to copy, redistribute and
  7933. modify it.  The comments at the beginning of `require.scm' and
  7934. `macwork.scm' illustrate copyright and appropriate terms.
  7935.   If your code or changes amount to less than about 10 lines, you do not
  7936. need to add your copyright or send a disclaimer.
  7937. Putting code into the Public Domain
  7938. -----------------------------------
  7939.   In order to put code in the public domain you should sign a copyright
  7940. disclaimer and send it to the SLIB maintainer.  Contact jaffer @              |
  7941. ai.mit.edu for the address to mail the disclaimer to.                         |
  7942.      I, NAME, hereby affirm that I have placed the software package
  7943.      NAME in the public domain.
  7944.      I affirm that I am the sole author and sole copyright holder for
  7945.      the software package, that I have the right to place this software
  7946.      package in the public domain, and that I will do nothing to
  7947.      undermine this status in the future.
  7948.                                                      SIGNATURE AND DATE
  7949.   This wording assumes that you are the sole author.  If you are not the
  7950. sole author, the wording needs to be different.  If you don't want to be
  7951. bothered with sending a letter every time you release or modify a
  7952. module, make your letter say that it also applies to your future
  7953. revisions of that module.
  7954.   Make sure no employer has any claim to the copyright on the work you
  7955. are submitting.  If there is any doubt, create a copyright disclaimer
  7956. and have your employer sign it.  Mail the signed disclaimer to the SLIB
  7957. maintainer.  Contact jaffer @ ai.mit.edu for the address to mail the
  7958. disclaimer to.  An example disclaimer follows.
  7959. Explicit copying terms
  7960. ----------------------
  7961. If you submit more than about 10 lines of code which you are not placing
  7962. into the Public Domain (by sending me a disclaimer) you need to:
  7963.    * Arrange that your name appears in a copyright line for the
  7964.      appropriate year.   Multiple copyright lines are acceptable.
  7965.    * With your copyright line, specify any terms you require to be
  7966.      different from those already in the file.
  7967.    * Make sure no employer has any claim to the copyright on the work
  7968.      you are submitting.  If there is any doubt, create a copyright
  7969.      disclaimer and have your employer sign it.  Mail the signed
  7970.      disclaim to the SLIB maintainer.  Contact jaffer @ ai.mit.edu for
  7971.      the address to mail the disclaimer to.
  7972. Example: Company Copyright Disclaimer
  7973. -------------------------------------
  7974.   This disclaimer should be signed by a vice president or general
  7975. manager of the company.  If you can't get at them, anyone else
  7976. authorized to license out software produced there will do.  Here is a
  7977. sample wording:
  7978.      EMPLOYER Corporation hereby disclaims all copyright interest in
  7979.      the program PROGRAM written by NAME.
  7980.      EMPLOYER Corporation affirms that it has no other intellectual
  7981.      property interest that would undermine this release, and will do
  7982.      nothing to undermine it in the future.
  7983.      SIGNATURE AND DATE,
  7984.      NAME, TITLE, EMPLOYER Corporation
  7985. File: slib.info,  Node: Index,  Prev: About SLIB,  Up: Top
  7986. Procedure and Macro Index
  7987. *************************
  7988.   This is an alphabetical list of all the procedures and macros in SLIB.
  7989. * Menu:
  7990. * -:                                     Multi-argument / and -.
  7991. * -1+:                                   Rev2 Procedures.
  7992. * /:                                     Multi-argument / and -.
  7993. * 1+:                                    Rev2 Procedures.
  7994. * <=?:                                   Rev2 Procedures.
  7995. * <?:                                    Rev2 Procedures.
  7996. * =?:                                    Rev2 Procedures.
  7997. * >=?:                                   Rev2 Procedures.
  7998. * >?:                                    Rev2 Procedures.
  7999. * absolute-path?:                        System Interface.                    |
  8000. * add-domain:                            Database Utilities.
  8001. * add-process!:                          Multi-Processing.
  8002. * add-setter:                            Setters.
  8003. * adjoin:                                Lists as sets.
  8004. * adjoin-parameters!:                    Parameter lists.
  8005. * alarm:                                 Multi-Processing.
  8006. * alarm-interrupt:                       Multi-Processing.
  8007. * alist->wt-tree:                        Construction of Weight-Balanced Trees.
  8008. * alist-associator:                      Association Lists.
  8009. * alist-for-each:                        Association Lists.
  8010. * alist-inquirer:                        Association Lists.
  8011. * alist-map:                             Association Lists.
  8012. * alist-remover:                         Association Lists.
  8013. * and?:                                  Non-List functions.
  8014. * any?:                                  Collections.
  8015. * append!:                               Rev2 Procedures.
  8016. * apply:                                 Multi-argument Apply.
  8017. * array-1d-ref:                          Arrays.
  8018. * array-1d-set!:                         Arrays.
  8019. * array-2d-ref:                          Arrays.
  8020. * array-2d-set!:                         Arrays.
  8021. * array-3d-ref:                          Arrays.
  8022. * array-3d-set!:                         Arrays.
  8023. * array-copy!:                           Array Mapping.
  8024. * array-dimensions:                      Arrays.
  8025. * array-for-each:                        Array Mapping.
  8026. * array-in-bounds?:                      Arrays.
  8027. * array-index-map!:                      Array Mapping.
  8028. * array-indexes:                         Array Mapping.
  8029. * array-map!:                            Array Mapping.
  8030. * array-rank:                            Arrays.
  8031. * array-ref:                             Arrays.
  8032. * array-set!:                            Arrays.
  8033. * array-shape:                           Arrays.
  8034. * array?:                                Arrays.
  8035. * asctime:                               Posix Time.
  8036. * ash:                                   Bit-Twiddling.
  8037. * atom?:                                 Non-List functions.
  8038. * batch:apply-chop-to-fit:               Batch.
  8039. * batch:call-with-output-script:         Batch.
  8040. * batch:comment:                         Batch.
  8041. * batch:delete-file:                     Batch.
  8042. * batch:initialize!:                     Batch.
  8043. * batch:lines->file:                     Batch.
  8044. * batch:rename-file:                     Batch.
  8045. * batch:run-script:                      Batch.
  8046. * batch:system:                          Batch.
  8047. * batch:try-system:                      Batch.
  8048. * bit-extract:                           Bit-Twiddling.
  8049. * bit-field:                             Bit-Twiddling.
  8050. * bitwise-if:                            Bit-Twiddling.
  8051. * break:                                 Breakpoints.
  8052. * break-all:                             Debug.
  8053. * breakf:                                Breakpoints.
  8054. * breakpoint:                            Breakpoints.
  8055. * browse:                                Database Browser.
  8056. * browse-url-netscape:                   System Interface.                    |
  8057. * butlast:                               Lists as sequences.
  8058. * butnthcdr:                             Lists as sequences.
  8059. * byte-ref:                              Byte.
  8060. * byte-set!:                             Byte.
  8061. * bytes:                                 Byte.
  8062. * bytes->list:                           Byte.
  8063. * bytes-length:                          Byte.
  8064. * call-with-dynamic-binding:             Dynamic Data Type.
  8065. * call-with-input-string:                String Ports.
  8066. * call-with-output-string:               String Ports.
  8067. * call-with-tmpnam:                      System Interface.                    |
  8068. * call-with-values:                      Values.
  8069. * capture-syntactic-environment:         Syntactic Closures.
  8070. * cart-prod-tables:                      Relational Database Operations.
  8071. * catalog->html:                         HTML HTTP and CGI.                   |
  8072. * catalog->page:                         HTML HTTP and CGI.                   |
  8073. * cgi:read-query-string:                 HTML HTTP and CGI.
  8074. * cgi:serve-command:                     HTML HTTP and CGI.
  8075. * chap:next-string:                      Chapter Ordering.
  8076. * chap:string<=?:                        Chapter Ordering.
  8077. * chap:string<?:                         Chapter Ordering.
  8078. * chap:string>=?:                        Chapter Ordering.
  8079. * chap:string>?:                         Chapter Ordering.
  8080. * check-parameters:                      Parameter lists.
  8081. * close-base:                            Base Table.
  8082. * close-database:                        Relational Database Operations.
  8083. * close-table:                           Table Operations.
  8084. * coerce:                                Non-List functions.
  8085. * collection?:                           Collections.
  8086. * combined-rulesets:                     Commutative Rings.
  8087. * command->html:                         HTML HTTP and CGI.
  8088. * continue:                              Breakpoints.
  8089. * copy-bit:                              Bit-Twiddling.
  8090. * copy-bit-field:                        Bit-Twiddling.
  8091. * copy-list:                             List construction.
  8092. * copy-random-state:                     Random Numbers.                      |
  8093. * copy-tree:                             Tree Operations.
  8094. * create-database <1>:                   Database Utilities.
  8095. * create-database:                       Creating and Opening Relational Databases.
  8096. * create-report:                         Database Reports.
  8097. * create-table:                          Relational Database Operations.
  8098. * create-view:                           Relational Database Operations.
  8099. * cring:define-rule:                     Commutative Rings.
  8100. * ctime:                                 Posix Time.
  8101. * current-directory:                     System Interface.                    |
  8102. * current-error-port:                    Input/Output.
  8103. * current-input-port <1>:                Byte.
  8104. * current-input-port:                    Ruleset Definition and Use.
  8105. * current-output-port:                   Byte.
  8106. * current-time:                          Time and Date.                       |
  8107. * debug:breakf:                          Breakpoints.
  8108. * debug:tracef:                          Trace.
  8109. * debug:unbreakf:                        Breakpoints.
  8110. * debug:untracef:                        Trace.
  8111. * decode-universal-time:                 Common-Lisp Time.
  8112. * define-access-operation:               Setters.
  8113. * define-operation:                      Yasos interface.
  8114. * define-predicate:                      Yasos interface.
  8115. * define-record:                         Structures.
  8116. * define-syntax:                         Macro by Example.
  8117. * define-tables:                         Database Utilities.
  8118. * defmacro:                              Defmacro.
  8119. * defmacro:eval:                         Defmacro.
  8120. * defmacro:expand*:                      Defmacro.
  8121. * defmacro:load:                         Defmacro.
  8122. * defmacro?:                             Defmacro.
  8123. * delete <1>:                            Destructive list operations.
  8124. * delete:                                Base Table.
  8125. * delete*:                               Base Table.
  8126. * delete-domain:                         Database Utilities.
  8127. * delete-file:                           Input/Output.
  8128. * delete-if:                             Destructive list operations.
  8129. * delete-if-not:                         Destructive list operations.
  8130. * delete-table:                          Relational Database Operations.
  8131. * dequeue!:                              Queues.
  8132. * difftime:                              Time and Date.                       |
  8133. * display-file:                          Line I/O.                            |
  8134. * do-elts:                               Collections.
  8135. * do-keys:                               Collections.
  8136. * domain-checker:                        Database Utilities.
  8137. * dynamic-ref:                           Dynamic Data Type.
  8138. * dynamic-set!:                          Dynamic Data Type.
  8139. * dynamic-wind:                          Dynamic-Wind.
  8140. * dynamic?:                              Dynamic Data Type.
  8141. * empty?:                                Collections.
  8142. * encode-universal-time:                 Common-Lisp Time.
  8143. * enquque!:                              Queues.
  8144. * equal?:                                Byte.
  8145. * eval:                                  Eval.
  8146. * every:                                 Lists as sets.
  8147. * every?:                                Collections.
  8148. * extended-euclid:                       Modular Arithmetic.
  8149. * factor:                                Prime Numbers.
  8150. * file-exists?:                          Input/Output.
  8151. * filename:match-ci??:                   Filenames.
  8152. * filename:match??:                      Filenames.
  8153. * filename:substitute-ci??:              Filenames.                           |
  8154. * filename:substitute??:                 Filenames.                           |
  8155. * fill-empty-parameters:                 Parameter lists.
  8156. * find-if:                               Lists as sets.
  8157. * find-string-from-port?:                String Search.
  8158. * fluid-let:                             Fluid-Let.
  8159. * for-each-elt:                          Collections.
  8160. * for-each-key <1>:                      Collections.
  8161. * for-each-key:                          Base Table.
  8162. * for-each-row:                          Table Operations.
  8163. * force-output:                          Input/Output.
  8164. * format:                                Format Interface.
  8165. * fprintf:                               Standard Formatted Output.
  8166. * fscanf:                                Standard Formatted Input.
  8167. * ftp-upload:                            System Interface.                    |
  8168. * generic-write:                         Generic-Write.
  8169. * gentemp:                               Defmacro.
  8170. * get:                                   Table Operations.
  8171. * get*:                                  Table Operations.
  8172. * get-decoded-time:                      Common-Lisp Time.
  8173. * get-method:                            Object.                              |
  8174. * get-universal-time:                    Common-Lisp Time.
  8175. * getenv:                                System Interface.
  8176. * getopt:                                Getopt.
  8177. * getopt--:                              Getopt.
  8178. * getopt->arglist:                       Getopt Parameter lists.
  8179. * getopt->parameter-list:                Getopt Parameter lists.
  8180. * glob-pattern?:                         System Interface.                    |
  8181. * gmktime:                               Posix Time.
  8182. * gmtime:                                Posix Time.
  8183. * gtime:                                 Posix Time.
  8184. * has-duplicates?:                       Lists as sets.
  8185. * hash:                                  Hashing.
  8186. * hash-associator:                       Hash Tables.
  8187. * hash-for-each:                         Hash Tables.
  8188. * hash-inquirer:                         Hash Tables.
  8189. * hash-map:                              Hash Tables.
  8190. * hash-remover:                          Hash Tables.
  8191. * hashq:                                 Hashing.
  8192. * hashv:                                 Hashing.
  8193. * heap-extract-max!:                     Priority Queues.
  8194. * heap-insert!:                          Priority Queues.
  8195. * heap-length:                           Priority Queues.
  8196. * home-vicinity:                         Vicinity.                            |
  8197. * html:comment:                          HTML HTTP and CGI.
  8198. * html:end-form:                         HTML HTTP and CGI.
  8199. * html:end-page:                         HTML HTTP and CGI.
  8200. * html:end-table:                        HTML HTTP and CGI.                   |
  8201. * html:heading:                          HTML HTTP and CGI.                   |
  8202. * html:href-heading:                     HTML HTTP and CGI.                   |
  8203. * html:pre:                              HTML HTTP and CGI.                   |
  8204. * html:start-form:                       HTML HTTP and CGI.
  8205. * html:start-page:                       HTML HTTP and CGI.
  8206. * html:start-table:                      HTML HTTP and CGI.                   |
  8207. * http:read-request-line:                HTML HTTP and CGI.
  8208. * http:serve-query:                      HTML HTTP and CGI.
  8209. * identifier=?:                          Syntactic Closures.
  8210. * identifier?:                           Syntactic Closures.
  8211. * identity:                              Legacy.
  8212. * implementation-vicinity:               Vicinity.
  8213. * in-vicinity:                           Vicinity.
  8214. * init-debug:                            Breakpoints.
  8215. * integer-expt:                          Bit-Twiddling.
  8216. * integer-length:                        Bit-Twiddling.
  8217. * integer-sqrt:                          Root Finding.
  8218. * interaction-environment:               Eval.
  8219. * intersection:                          Lists as sets.
  8220. * jacobi-symbol:                         Prime Numbers.
  8221. * kill-process!:                         Multi-Processing.
  8222. * kill-table:                            Base Table.
  8223. * laguerre:find-polynomial-root:         Root Finding.
  8224. * laguerre:find-root:                    Root Finding.
  8225. * last:                                  Lists as sequences.
  8226. * last-pair:                             Legacy.
  8227. * library-vicinity:                      Vicinity.
  8228. * list*:                                 List construction.
  8229. * list->bytes:                           Byte.
  8230. * list->string:                          Rev4 Optional Procedures.
  8231. * list->vector:                          Rev4 Optional Procedures.
  8232. * list-tail:                             Rev4 Optional Procedures.
  8233. * load-option:                           Weight-Balanced Trees.
  8234. * localtime:                             Posix Time.
  8235. * logand:                                Bit-Twiddling.
  8236. * logbit?:                               Bit-Twiddling.
  8237. * logcount:                              Bit-Twiddling.
  8238. * logior:                                Bit-Twiddling.
  8239. * lognot:                                Bit-Twiddling.
  8240. * logtest:                               Bit-Twiddling.
  8241. * logxor:                                Bit-Twiddling.
  8242. * macro:eval <1>:                        Syntax-Case Macros.
  8243. * macro:eval <2>:                        Syntactic Closures.
  8244. * macro:eval <3>:                        Macros That Work.
  8245. * macro:eval:                            R4RS Macros.
  8246. * macro:expand <1>:                      Syntax-Case Macros.
  8247. * macro:expand <2>:                      Syntactic Closures.
  8248. * macro:expand <3>:                      Macros That Work.
  8249. * macro:expand:                          R4RS Macros.
  8250. * macro:load <1>:                        Syntax-Case Macros.
  8251. * macro:load <2>:                        Syntactic Closures.
  8252. * macro:load <3>:                        Macros That Work.
  8253. * macro:load:                            R4RS Macros.
  8254. * macroexpand:                           Defmacro.
  8255. * macroexpand-1:                         Defmacro.
  8256. * macwork:eval:                          Macros That Work.
  8257. * macwork:expand:                        Macros That Work.
  8258. * macwork:load:                          Macros That Work.
  8259. * make-:                                 Structures.
  8260. * make-array:                            Arrays.
  8261. * make-atval:                            HTML HTTP and CGI.                   |
  8262. * make-base:                             Base Table.
  8263. * make-bytes:                            Byte.
  8264. * make-command-server:                   Database Utilities.
  8265. * make-directory:                        System Interface.                    |
  8266. * make-dynamic:                          Dynamic Data Type.
  8267. * make-generic-method:                   Object.                              |
  8268. * make-generic-predicate:                Object.                              |
  8269. * make-getter:                           Base Table.
  8270. * make-hash-table:                       Hash Tables.
  8271. * make-heap:                             Priority Queues.
  8272. * make-key->list:                        Base Table.
  8273. * make-key-extractor:                    Base Table.
  8274. * make-keyifier-1:                       Base Table.
  8275. * make-list:                             List construction.
  8276. * make-list-keyifier:                    Base Table.
  8277. * make-method!:                          Object.                              |
  8278. * make-object:                           Object.                              |
  8279. * make-parameter-list:                   Parameter lists.
  8280. * make-plain:                            HTML HTTP and CGI.                   |
  8281. * make-port-crc:                         Cyclic Checksum.
  8282. * make-predicate!:                       Object.                              |
  8283. * make-promise:                          Promises.
  8284. * make-putter:                           Base Table.
  8285. * make-queue:                            Queues.
  8286. * make-random-state:                     Random Numbers.
  8287. * make-record-type:                      Records.
  8288. * make-relational-system:                Creating and Opening Relational Databases.
  8289. * make-row-converter:                    HTML HTTP and CGI.                   |
  8290. * make-ruleset:                          Commutative Rings.
  8291. * make-shared-array:                     Arrays.
  8292. * make-sierpinski-indexer:               Hashing.
  8293. * make-syntactic-closure:                Syntactic Closures.
  8294. * make-table:                            Base Table.
  8295. * make-vicinity:                         Vicinity.
  8296. * make-wt-tree:                          Construction of Weight-Balanced Trees.
  8297. * make-wt-tree-type:                     Construction of Weight-Balanced Trees.
  8298. * map-elts:                              Collections.
  8299. * map-key:                               Base Table.
  8300. * map-keys:                              Collections.
  8301. * member-if:                             Lists as sets.
  8302. * merge:                                 Sorting.
  8303. * merge!:                                Sorting.
  8304. * mktime:                                Posix Time.
  8305. * modular::                              Modular Arithmetic.
  8306. * modular:*:                             Modular Arithmetic.
  8307. * modular:+:                             Modular Arithmetic.
  8308. * modular:expt:                          Modular Arithmetic.
  8309. * modular:invert:                        Modular Arithmetic.
  8310. * modular:invertable?:                   Modular Arithmetic.
  8311. * modular:negate:                        Modular Arithmetic.
  8312. * modular:normalize:                     Modular Arithmetic.
  8313. * modulus->integer:                      Modular Arithmetic.
  8314. * must-be-first:                         Batch.
  8315. * must-be-last:                          Batch.
  8316. * nconc:                                 Destructive list operations.
  8317. * newton:find-root:                      Root Finding.
  8318. * newtown:find-integer-root:             Root Finding.
  8319. * notany:                                Lists as sets.
  8320. * notevery:                              Lists as sets.
  8321. * nreverse:                              Destructive list operations.
  8322. * nthcdr:                                Lists as sequences.
  8323. * null-directory?:                       System Interface.                    |
  8324. * null-environment:                      Eval.
  8325. * object:                                Yasos interface.
  8326. * object->limited-string:                Object-To-String.
  8327. * object->string:                        Object-To-String.
  8328. * object-with-ancestors:                 Yasos interface.
  8329. * object?:                               Object.                              |
  8330. * offset-time:                           Time and Date.                       |
  8331. * open-base:                             Base Table.
  8332. * open-database <1>:                     Database Utilities.
  8333. * open-database:                         Creating and Opening Relational Databases.
  8334. * open-database!:                        Database Utilities.
  8335. * open-table <1>:                        Relational Database Operations.
  8336. * open-table:                            Base Table.
  8337. * operate-as:                            Yasos interface.
  8338. * or?:                                   Non-List functions.
  8339. * ordered-for-each-key:                  Base Table.
  8340. * os->batch-dialect:                     Batch.
  8341. * output-port-height:                    Input/Output.
  8342. * output-port-width:                     Input/Output.
  8343. * parameter-list->arglist:               Parameter lists.
  8344. * parameter-list-expand:                 Parameter lists.
  8345. * parameter-list-ref:                    Parameter lists.
  8346. * parse-ftp-address:                     System Interface.                    |
  8347. * path->url:                             System Interface.                    |
  8348. * plot!:                                 Plotting.
  8349. * position:                              Lists as sequences.
  8350. * pprint-file:                           Pretty-Print.
  8351. * pprint-filter-file:                    Pretty-Print.
  8352. * prec:commentfix:                       Grammar Rule Definition.
  8353. * prec:define-grammar:                   Ruleset Definition and Use.
  8354. * prec:delim:                            Grammar Rule Definition.
  8355. * prec:infix:                            Grammar Rule Definition.
  8356. * prec:inmatchfix:                       Grammar Rule Definition.
  8357. * prec:make-led:                         Nud and Led Definition.
  8358. * prec:make-nud:                         Nud and Led Definition.
  8359. * prec:matchfix:                         Grammar Rule Definition.
  8360. * prec:nary:                             Grammar Rule Definition.
  8361. * prec:nofix:                            Grammar Rule Definition.
  8362. * prec:parse:                            Ruleset Definition and Use.
  8363. * prec:postfix:                          Grammar Rule Definition.
  8364. * prec:prefix:                           Grammar Rule Definition.
  8365. * prec:prestfix:                         Grammar Rule Definition.
  8366. * predicate->asso:                       Association Lists.
  8367. * predicate->hash:                       Hash Tables.
  8368. * predicate->hash-asso:                  Hash Tables.
  8369. * present?:                              Base Table.
  8370. * pretty-print:                          Pretty-Print.
  8371. * prime?:                                Prime Numbers.
  8372. * primes<:                               Prime Numbers.
  8373. * primes>:                               Prime Numbers.
  8374. * print:                                 Yasos interface.
  8375. * printf:                                Standard Formatted Output.
  8376. * process:schedule!:                     Multi-Processing.
  8377. * program-vicinity:                      Vicinity.
  8378. * project-table:                         Relational Database Operations.
  8379. * provide <1>:                           Require.
  8380. * provide:                               Feature.
  8381. * provided? <1>:                         Require.
  8382. * provided?:                             Feature.
  8383. * qp:                                    Quick Print.
  8384. * qpn:                                   Quick Print.
  8385. * qpr:                                   Quick Print.
  8386. * queue-empty?:                          Queues.
  8387. * queue-front:                           Queues.
  8388. * queue-pop!:                            Queues.
  8389. * queue-push!:                           Queues.
  8390. * queue-rear:                            Queues.
  8391. * queue?:                                Queues.
  8392. * random:                                Random Numbers.
  8393. * random:exp:                            Random Numbers.
  8394. * random:hollow-sphere!:                 Random Numbers.
  8395. * random:normal:                         Random Numbers.
  8396. * random:normal-vector!:                 Random Numbers.
  8397. * random:solid-sphere!:                  Random Numbers.
  8398. * random:uniform:                        Random Numbers.
  8399. * rationalize:                           Rationalize.
  8400. * read-byte:                             Byte.
  8401. * read-command:                          Command Line.
  8402. * read-line:                             Line I/O.
  8403. * read-line!:                            Line I/O.
  8404. * read-options-file:                     Command Line.
  8405. * record-accessor:                       Records.
  8406. * record-constructor:                    Records.
  8407. * record-modifier:                       Records.
  8408. * record-predicate:                      Records.
  8409. * reduce <1>:                            Lists as sequences.
  8410. * reduce:                                Collections.
  8411. * reduce-init:                           Lists as sequences.
  8412. * remove:                                Lists as sets.
  8413. * remove-duplicates:                     Lists as sets.
  8414. * remove-if:                             Lists as sets.
  8415. * remove-if-not:                         Lists as sets.
  8416. * remove-setter-for:                     Setters.
  8417. * repl:quit:                             Repl.
  8418. * repl:top-level:                        Repl.
  8419. * replace-suffix:                        Filenames.
  8420. * require <1>:                           Require.
  8421. * require <2>:                           Catalog Compilation.
  8422. * require:                               Requesting Features.
  8423. * require:feature->path <1>:             Require.
  8424. * require:feature->path:                 Requesting Features.
  8425. * restrict-table:                        Relational Database Operations.
  8426. * row:delete:                            Table Operations.
  8427. * row:delete*:                           Table Operations.
  8428. * row:insert:                            Table Operations.
  8429. * row:insert*:                           Table Operations.
  8430. * row:remove:                            Table Operations.
  8431. * row:remove*:                           Table Operations.
  8432. * row:retrieve:                          Table Operations.
  8433. * row:retrieve*:                         Table Operations.
  8434. * row:update:                            Table Operations.
  8435. * row:update*:                           Table Operations.
  8436. * scanf:                                 Standard Formatted Input.
  8437. * scanf-read-list:                       Standard Formatted Input.
  8438. * scheme-report-environment:             Eval.
  8439. * schmooz:                               Schmooz.
  8440. * secant:find-bracketed-root:            Root Finding.                        |
  8441. * secant:find-root:                      Root Finding.                        |
  8442. * seed->random-state:                    Random Numbers.                      |
  8443. * serve-urlencoded-command:              HTML HTTP and CGI.
  8444. * set:                                   Setters.
  8445. * set-:                                  Structures.
  8446. * set-difference:                        Lists as sets.
  8447. * Setter:                                Collections.
  8448. * setter:                                Setters.
  8449. * singleton-wt-tree:                     Construction of Weight-Balanced Trees.
  8450. * size <1>:                              Collections.
  8451. * size:                                  Yasos interface.
  8452. * slib:error:                            System.
  8453. * slib:eval:                             System.
  8454. * slib:eval-load:                        System.
  8455. * slib:exit:                             System.
  8456. * slib:load:                             System.
  8457. * slib:load-compiled:                    System.
  8458. * slib:load-source:                      System.
  8459. * slib:report:                           Configuration.
  8460. * slib:report-version:                   Configuration.
  8461. * slib:warn:                             System.
  8462. * software-type:                         Configuration.
  8463. * some:                                  Lists as sets.
  8464. * sort:                                  Sorting.
  8465. * sort!:                                 Sorting.
  8466. * sorted?:                               Sorting.
  8467. * soundex:                               Hashing.
  8468. * sprintf:                               Standard Formatted Output.
  8469. * sscanf:                                Standard Formatted Input.
  8470. * string->list:                          Rev4 Optional Procedures.
  8471. * string-capitalize:                     String-Case.
  8472. * string-captialize!:                    String-Case.
  8473. * string-ci->symbol:                     String-Case.
  8474. * string-copy:                           Rev4 Optional Procedures.
  8475. * string-downcase:                       String-Case.
  8476. * string-downcase!:                      String-Case.
  8477. * string-fill!:                          Rev4 Optional Procedures.
  8478. * string-index:                          String Search.
  8479. * string-index-ci:                       String Search.
  8480. * string-join:                           Batch.
  8481. * string-null?:                          Rev2 Procedures.
  8482. * string-reverse-index:                  String Search.
  8483. * string-reverse-index-ci:               String Search.
  8484. * string-subst:                          String Search.
  8485. * string-upcase:                         String-Case.
  8486. * string-upcase!:                        String-Case.
  8487. * sub-vicinity:                          Vicinity.
  8488. * subst:                                 Tree Operations.
  8489. * substq:                                Tree Operations.
  8490. * substring-ci?:                         String Search.
  8491. * substring-fill!:                       Rev2 Procedures.
  8492. * substring-move-left!:                  Rev2 Procedures.
  8493. * substring-move-right!:                 Rev2 Procedures.
  8494. * substring?:                            String Search.
  8495. * substv:                                Tree Operations.
  8496. * supported-key-type?:                   Base Table.
  8497. * supported-type?:                       Base Table.
  8498. * symmetric:modulus:                     Modular Arithmetic.
  8499. * sync-base:                             Base Table.
  8500. * syncase:eval:                          Syntax-Case Macros.
  8501. * syncase:expand:                        Syntax-Case Macros.
  8502. * syncase:load:                          Syntax-Case Macros.
  8503. * synclo:eval:                           Syntactic Closures.
  8504. * synclo:expand:                         Syntactic Closures.
  8505. * synclo:load:                           Syntactic Closures.
  8506. * syntax-rules:                          Macro by Example.
  8507. * system:                                System Interface.
  8508. * table->html:                           HTML HTTP and CGI.                   |
  8509. * table->page:                           HTML HTTP and CGI.                   |
  8510. * table-exists?:                         Relational Database Operations.
  8511. * table-name->filename:                  HTML HTTP and CGI.                   |
  8512. * TAG:                                   Structures.
  8513. * tek40:draw:                            Tektronix Graphics Support.
  8514. * tek40:graphics:                        Tektronix Graphics Support.
  8515. * tek40:init:                            Tektronix Graphics Support.
  8516. * tek40:linetype:                        Tektronix Graphics Support.
  8517. * tek40:move:                            Tektronix Graphics Support.
  8518. * tek40:put-text:                        Tektronix Graphics Support.
  8519. * tek40:reset:                           Tektronix Graphics Support.
  8520. * tek40:text:                            Tektronix Graphics Support.
  8521. * tek41:draw:                            Tektronix Graphics Support.
  8522. * tek41:encode-int:                      Tektronix Graphics Support.
  8523. * tek41:encode-x-y:                      Tektronix Graphics Support.
  8524. * tek41:graphics:                        Tektronix Graphics Support.
  8525. * tek41:init:                            Tektronix Graphics Support.
  8526. * tek41:move:                            Tektronix Graphics Support.
  8527. * tek41:point:                           Tektronix Graphics Support.
  8528. * tek41:reset:                           Tektronix Graphics Support.
  8529. * time-zone:                             Time Zone.
  8530. * tmpnam:                                Input/Output.
  8531. * tok:char-group:                        Token definition.
  8532. * topological-sort:                      Topological Sort.
  8533. * trace:                                 Trace.
  8534. * trace-all:                             Debug.
  8535. * tracef:                                Trace.
  8536. * transcript-off:                        Transcripts.
  8537. * transcript-on:                         Transcripts.
  8538. * transformer:                           Syntactic Closures.
  8539. * truncate-up-to:                        Batch.
  8540. * tsort:                                 Topological Sort.
  8541. * two-arg:-:                             Multi-argument / and -.
  8542. * two-arg:/:                             Multi-argument / and -.
  8543. * two-arg:apply:                         Multi-argument Apply.
  8544. * type-of:                               Non-List functions.
  8545. * tz:params:                             Time Zone.
  8546. * tzset:                                 Time Zone.
  8547. * unbreak:                               Breakpoints.
  8548. * unbreakf:                              Breakpoints.
  8549. * union:                                 Lists as sets.
  8550. * unmake-method!:                        Object.                              |
  8551. * untrace:                               Trace.
  8552. * untracef:                              Trace.
  8553. * user-email-address:                    System Interface.                    |
  8554. * user-vicinity:                         Vicinity.
  8555. * values:                                Values.
  8556. * variant-case:                          Structures.
  8557. * vector->list:                          Rev4 Optional Procedures.
  8558. * vector-fill!:                          Rev4 Optional Procedures.
  8559. * with-input-from-file:                  With-File.
  8560. * with-output-to-file:                   With-File.
  8561. * write-base:                            Base Table.
  8562. * write-byte:                            Byte.
  8563. * write-database:                        Relational Database Operations.
  8564. * write-line:                            Line I/O.
  8565. * wt-tree/add:                           Basic Operations on Weight-Balanced Trees.
  8566. * wt-tree/add!:                          Basic Operations on Weight-Balanced Trees.
  8567. * wt-tree/delete:                        Basic Operations on Weight-Balanced Trees.
  8568. * wt-tree/delete!:                       Basic Operations on Weight-Balanced Trees.
  8569. * wt-tree/delete-min:                    Indexing Operations on Weight-Balanced Trees.
  8570. * wt-tree/delete-min!:                   Indexing Operations on Weight-Balanced Trees.
  8571. * wt-tree/difference:                    Advanced Operations on Weight-Balanced Trees.
  8572. * wt-tree/empty?:                        Basic Operations on Weight-Balanced Trees.
  8573. * wt-tree/fold:                          Advanced Operations on Weight-Balanced Trees.
  8574. * wt-tree/for-each:                      Advanced Operations on Weight-Balanced Trees.
  8575. * wt-tree/index:                         Indexing Operations on Weight-Balanced Trees.
  8576. * wt-tree/index-datum:                   Indexing Operations on Weight-Balanced Trees.
  8577. * wt-tree/index-pair:                    Indexing Operations on Weight-Balanced Trees.
  8578. * wt-tree/intersection:                  Advanced Operations on Weight-Balanced Trees.
  8579. * wt-tree/lookup:                        Basic Operations on Weight-Balanced Trees.
  8580. * wt-tree/member?:                       Basic Operations on Weight-Balanced Trees.
  8581. * wt-tree/min:                           Indexing Operations on Weight-Balanced Trees.
  8582. * wt-tree/min-datum:                     Indexing Operations on Weight-Balanced Trees.
  8583. * wt-tree/min-pair:                      Indexing Operations on Weight-Balanced Trees.
  8584. * wt-tree/rank:                          Indexing Operations on Weight-Balanced Trees.
  8585. * wt-tree/set-equal?:                    Advanced Operations on Weight-Balanced Trees.
  8586. * wt-tree/size:                          Basic Operations on Weight-Balanced Trees.
  8587. * wt-tree/split<:                        Advanced Operations on Weight-Balanced Trees.
  8588. * wt-tree/split>:                        Advanced Operations on Weight-Balanced Trees.
  8589. * wt-tree/subset?:                       Advanced Operations on Weight-Balanced Trees.
  8590. * wt-tree/union:                         Advanced Operations on Weight-Balanced Trees.
  8591. * wt-tree?:                              Basic Operations on Weight-Balanced Trees.
  8592. Variable Index
  8593. **************
  8594.   This is an alphabetical list of all the global variables in SLIB.
  8595. * Menu:
  8596. * *catalog*:                             Require.
  8597. * *features*:                            Require.
  8598. * *html:output-port*:                    HTML HTTP and CGI.
  8599. * *modules*:                             Require.
  8600. * *optarg*:                              Getopt.
  8601. * *optind*:                              Getopt.
  8602. * *qp-width*:                            Quick Print.
  8603. * *random-state*:                        Random Numbers.
  8604. * *ruleset*:                             Commutative Rings.
  8605. * *syn-defs*:                            Ruleset Definition and Use.
  8606. * *syn-ignore-whitespace*:               Ruleset Definition and Use.
  8607. * *timezone*:                            Time Zone.
  8608. * batch:platform:                        Batch.
  8609. * catalog-id:                            Base Table.
  8610. * char-code-limit:                       Configuration.
  8611. * charplot:height:                       Plotting.
  8612. * charplot:width:                        Plotting.
  8613. * column-domains:                        Table Operations.
  8614. * column-foreigns:                       Table Operations.
  8615. * column-names:                          Table Operations.
  8616. * column-types:                          Table Operations.
  8617. * daylight?:                             Time Zone.
  8618. * distribute*:                           Commutative Rings.
  8619. * distribute/:                           Commutative Rings.
  8620. * most-positive-fixnum:                  Configuration.
  8621. * nil:                                   Legacy.
  8622. * number-wt-type:                        Construction of Weight-Balanced Trees.
  8623. * primary-limit:                         Table Operations.
  8624. * prime:prngs:                           Prime Numbers.
  8625. * prime:trials:                          Prime Numbers.
  8626. * slib:form-feed:                        Configuration.
  8627. * slib:tab:                              Configuration.
  8628. * stderr:                                Standard Formatted I/O.
  8629. * stdin:                                 Standard Formatted I/O.
  8630. * stdout:                                Standard Formatted I/O.
  8631. * string-wt-type:                        Construction of Weight-Balanced Trees.
  8632. * t:                                     Legacy.
  8633. * tok:decimal-digits:                    Token definition.
  8634. * tok:lower-case:                        Token definition.
  8635. * tok:upper-case:                        Token definition.
  8636. * tok:whitespaces:                       Token definition.
  8637. * tzname:                                Time Zone.
  8638. Concept and Feature Index
  8639. *************************
  8640. * Menu:
  8641. * alist:                                 Association Lists.
  8642. * alist-table <1>:                       Creating and Opening Relational Databases.
  8643. * alist-table:                           Base Table.
  8644. * ange-ftp:                              System Interface.                    |
  8645. * array:                                 Arrays.
  8646. * array-for-each:                        Array Mapping.
  8647. * attribute-value:                       HTML HTTP and CGI.
  8648. * balanced binary trees:                 Weight-Balanced Trees.
  8649. * batch:                                 Batch.
  8650. * binary trees:                          Weight-Balanced Trees.
  8651. * binary trees, as discrete maps:        Weight-Balanced Trees.
  8652. * binary trees, as sets:                 Weight-Balanced Trees.
  8653. * break:                                 Breakpoints.
  8654. * byte:                                  Byte.
  8655. * calendar time <1>:                     Posix Time.                          |
  8656. * calendar time:                         Time and Date.                       |
  8657. * Calendar-Time:                         Posix Time.
  8658. * caltime:                               Posix Time.
  8659. * careful:                               Commutative Rings.
  8660. * catalog:                               Requesting Features.
  8661. * Catalog File:                          Library Catalogs.
  8662. * chapter-order:                         Chapter Ordering.
  8663. * charplot:                              Plotting.
  8664. * collect:                               Collections.
  8665. * command line:                          Command Line.
  8666. * commentfix:                            Precedence Parsing Overview.
  8667. * common-list-functions <1>:             Common List Functions.
  8668. * common-list-functions:                 Collections.
  8669. * commutative-ring:                      Commutative Rings.
  8670. * Coordinated Universal Time:            Posix Time.
  8671. * database-utilities <1>:                Database Utilities.
  8672. * database-utilities:                    Batch.
  8673. * debug <1>:                             Breakpoints.
  8674. * debug:                                 Debug.
  8675. * defmacroexpand <1>:                    Pretty-Print.
  8676. * defmacroexpand:                        Defmacro.
  8677. * delim:                                 Precedence Parsing Overview.
  8678. * discrete maps, using binary trees:     Weight-Balanced Trees.
  8679. * dynamic:                               Dynamic Data Type.
  8680. * dynamic-wind:                          Dynamic-Wind.
  8681. * Euclidean Domain:                      Commutative Rings.
  8682. * factor:                                Prime Numbers.
  8683. * feature <1>:                           About this manual.
  8684. * feature <2>:                           Requesting Features.
  8685. * feature:                               Feature.
  8686. * fluid-let <1>:                         Database Utilities.
  8687. * fluid-let:                             Fluid-Let.
  8688. * form:                                  HTML HTTP and CGI.
  8689. * format:                                Format.
  8690. * generic-write:                         Generic-Write.
  8691. * getit:                                 System Interface.                    |
  8692. * getopt <1>:                            Database Utilities.
  8693. * getopt:                                Getopt.
  8694. * glob <1>:                              Batch.
  8695. * glob:                                  Filenames.
  8696. * hash:                                  Hashing.
  8697. * hash-table:                            Hash Tables.
  8698. * HOME <1>:                              Vicinity.
  8699. * HOME:                                  Library Catalogs.
  8700. * homecat:                               Catalog Compilation.
  8701. * implcat:                               Catalog Compilation.
  8702. * infix:                                 Precedence Parsing Overview.
  8703. * inmatchfix:                            Precedence Parsing Overview.
  8704. * Left Denotation, led:                  Nud and Led Definition.
  8705. * line-i:                                Line I/O.
  8706. * logical:                               Bit-Twiddling.
  8707. * macro <1>:                             Repl.
  8708. * macro:                                 R4RS Macros.
  8709. * macro-by-example:                      Macro by Example.
  8710. * macros-that-work:                      Macros That Work.
  8711. * make-crc:                              Cyclic Checksum.
  8712. * match:                                 Base Table.
  8713. * match-key:                             Base Table.
  8714. * match-keys:                            Table Operations.
  8715. * matchfix:                              Precedence Parsing Overview.
  8716. * minimum field width (printf):          Standard Formatted Output.
  8717. * mkimpcat.scm:                          Catalog Compilation.
  8718. * mklibcat.scm:                          Catalog Compilation.
  8719. * modular:                               Modular Arithmetic.
  8720. * multiarg-apply:                        Multi-argument Apply.
  8721. * mutliarg:                              Multi-argument / and -.
  8722. * nary:                                  Precedence Parsing Overview.
  8723. * net-clients:                           System Interface.                    |
  8724. * nofix:                                 Precedence Parsing Overview.
  8725. * Null Denotation, nud:                  Nud and Led Definition.
  8726. * object:                                Object.                              |
  8727. * object->string:                        Object-To-String.
  8728. * oop:                                   Yasos.
  8729. * option, run-time-loadable:             Weight-Balanced Trees.
  8730. * options file:                          Command Line.
  8731. * package:                               Top.
  8732. * packages:                              Top.
  8733. * parameters <1>:                        Database Utilities.
  8734. * parameters <2>:                        Batch.
  8735. * parameters:                            Parameter lists.
  8736. * parse:                                 Precedence Parsing.
  8737. * plain-text:                            HTML HTTP and CGI.
  8738. * posix-time:                            Posix Time.
  8739. * postfix:                               Precedence Parsing Overview.
  8740. * pprint-file:                           Pretty-Print.
  8741. * PRE:                                   HTML HTTP and CGI.                   |
  8742. * precedence:                            Precedence Parsing.
  8743. * precision (printf):                    Standard Formatted Output.
  8744. * prefix:                                Precedence Parsing Overview.
  8745. * prestfix:                              Precedence Parsing Overview.
  8746. * pretty-print:                          Pretty-Print.
  8747. * primes:                                Prime Numbers.
  8748. * printf:                                Standard Formatted Output.
  8749. * priority-queue:                        Priority Queues.
  8750. * PRNG:                                  Random Numbers.
  8751. * process:                               Multi-Processing.
  8752. * promise:                               Promises.
  8753. * qp <1>:                                Quick Print.
  8754. * qp:                                    Getopt.
  8755. * query-string:                          HTML HTTP and CGI.
  8756. * queue:                                 Queues.
  8757. * random:                                Random Numbers.
  8758. * rationalize:                           Rationalize.
  8759. * read-command:                          Command Line.
  8760. * record:                                Records.
  8761. * relational-database:                   Relational Database.
  8762. * repl <1>:                              Repl.
  8763. * repl:                                  Syntax-Case Macros.
  8764. * rev2-procedures:                       Rev2 Procedures.
  8765. * rev3-report:                           Coding Standards.
  8766. * rev4-optional-procedures:              Rev4 Optional Procedures.
  8767. * ring, commutative:                     Commutative Rings.
  8768. * RNG:                                   Random Numbers.
  8769. * root:                                  Root Finding.
  8770. * run-time-loadable option:              Weight-Balanced Trees.
  8771. * scanf:                                 Standard Formatted Input.
  8772. * Scheme:                                Top.
  8773. * schmooz:                               Schmooz.
  8774. * session:                               Feature.
  8775. * sets, using binary trees:              Weight-Balanced Trees.
  8776. * sierpinski:                            Hashing.
  8777. * sitecat:                               Catalog Compilation.
  8778. * SLIB:                                  Top.
  8779. * slibcat:                               Catalog Compilation.
  8780. * sort:                                  Sorting.
  8781. * soundex:                               Hashing.
  8782. * stdio:                                 Standard Formatted I/O.
  8783. * string-case:                           String-Case.
  8784. * string-port:                           String Ports.
  8785. * string-search:                         String Search.
  8786. * struct:                                Structures.
  8787. * syntactic-closures:                    Syntactic Closures.
  8788. * syntax-case:                           Syntax-Case Macros.
  8789. * time:                                  Time and Date.                       |
  8790. * time-zone:                             Time Zone.
  8791. * topological-sort:                      Topological Sort.
  8792. * trace:                                 Trace.
  8793. * transcript:                            Transcripts.
  8794. * tree:                                  Tree Operations.
  8795. * trees, balanced binary:                Weight-Balanced Trees.
  8796. * tsort:                                 Topological Sort.
  8797. * TZ-string:                             Time Zone.
  8798. * Uniform Resource Locator:              System Interface.                    |
  8799. * Unique Factorization:                  Commutative Rings.
  8800. * usercat:                               Catalog Compilation.
  8801. * UTC:                                   Posix Time.
  8802. * values:                                Values.
  8803. * weight-balanced binary trees:          Weight-Balanced Trees.
  8804. * wild-card:                             Base Table.
  8805. * with-file:                             With-File.
  8806. * wt-tree:                               Weight-Balanced Trees.
  8807. * yasos:                                 Yasos.
  8808. Tag Table:
  8809. Node: Top
  8810. Node: The Library System
  8811. Node: Feature
  8812. Node: Requesting Features
  8813. Node: Library Catalogs
  8814. Node: Catalog Compilation
  8815. Node: Built-in Support
  8816. Node: Require
  8817. 10405
  8818. Node: Vicinity
  8819. 12898
  8820. Node: Configuration
  8821. 15865
  8822. Node: Input/Output
  8823. 18806
  8824. Node: Legacy
  8825. 20405
  8826. Node: System
  8827. 21247
  8828. Node: About this manual
  8829. 23739
  8830. Node: Scheme Syntax Extension Packages
  8831. 24296
  8832. Node: Defmacro
  8833. 24981
  8834. Node: R4RS Macros
  8835. 26931
  8836. Node: Macro by Example
  8837. 28186
  8838. Node: Macros That Work
  8839. 31062
  8840. Node: Syntactic Closures
  8841. 37120
  8842. Node: Syntax-Case Macros
  8843. 54553
  8844. Node: Fluid-Let
  8845. 58679
  8846. Node: Yasos
  8847. 59620
  8848. Node: Yasos terms
  8849. 60413
  8850. Node: Yasos interface
  8851. 61437
  8852. Node: Setters
  8853. 63512
  8854. Node: Yasos examples
  8855. 66153
  8856. Node: Textual Conversion Packages
  8857. 69625
  8858. Node: Precedence Parsing
  8859. 70201
  8860. Node: Precedence Parsing Overview
  8861. 70864
  8862. Node: Ruleset Definition and Use
  8863. 73061
  8864. Node: Token definition
  8865. 75442
  8866. Node: Nud and Led Definition
  8867. 77711
  8868. Node: Grammar Rule Definition
  8869. 80160
  8870. Node: Format
  8871. 87734
  8872. Node: Format Interface
  8873. 87982
  8874. Node: Format Specification
  8875. 89719
  8876. Node: Standard Formatted I/O
  8877. 99776
  8878. Node: Standard Formatted Output
  8879. 100342
  8880. Node: Standard Formatted Input
  8881. 109394
  8882. Node: Programs and Arguments
  8883. 116053
  8884. Node: Getopt
  8885. 116566
  8886. Node: Command Line
  8887. 122408
  8888. Node: Parameter lists
  8889. 125597
  8890. Node: Getopt Parameter lists
  8891. 129234
  8892. Node: Filenames
  8893. 131429
  8894. Node: Batch
  8895. 134846
  8896. Node: HTML HTTP and CGI
  8897. 142756
  8898. Node: Printing Scheme
  8899. 152961
  8900. Node: Generic-Write
  8901. 153284
  8902. Node: Object-To-String
  8903. 154687
  8904. Node: Pretty-Print
  8905. 155091
  8906. Node: Time and Date
  8907. 157037
  8908. Node: Time Zone
  8909. 158959
  8910. Node: Posix Time
  8911. 168656
  8912. Node: Common-Lisp Time
  8913. 170871
  8914. Node: Vector Graphics
  8915. 172450
  8916. Node: Tektronix Graphics Support
  8917. 172639
  8918. Node: Schmooz
  8919. 174013
  8920. Node: Mathematical Packages
  8921. 178239
  8922. Node: Bit-Twiddling
  8923. 178794
  8924. Node: Modular Arithmetic
  8925. 183385
  8926. Node: Prime Numbers
  8927. 185519
  8928. Node: Random Numbers
  8929. 186971
  8930. Node: Cyclic Checksum
  8931. 193593
  8932. Node: Plotting
  8933. 195303
  8934. Node: Root Finding
  8935. 197878
  8936. Node: Commutative Rings
  8937. 203071
  8938. Node: Determinant
  8939. 214457
  8940. Node: Database Packages
  8941. 214755
  8942. Node: Base Table
  8943. 215019
  8944. Node: Relational Database
  8945. 225177
  8946. Node: Motivations
  8947. 225961
  8948. Node: Creating and Opening Relational Databases
  8949. 231008
  8950. Node: Relational Database Operations
  8951. 233440
  8952. Node: Table Operations
  8953. 236237
  8954. Node: Catalog Representation
  8955. 244115
  8956. Node: Unresolved Issues
  8957. 247013
  8958. Node: Database Utilities
  8959. 249964
  8960. Node: Database Reports
  8961. 265619
  8962. Node: Database Browser
  8963. 269443
  8964. Node: Weight-Balanced Trees
  8965. 270504
  8966. Node: Construction of Weight-Balanced Trees
  8967. 274374
  8968. Node: Basic Operations on Weight-Balanced Trees
  8969. 277824
  8970. Node: Advanced Operations on Weight-Balanced Trees
  8971. 280789
  8972. Node: Indexing Operations on Weight-Balanced Trees
  8973. 286811
  8974. Node: Other Packages
  8975. 290725
  8976. Node: Data Structures
  8977. 291124
  8978. Node: Arrays
  8979. 291883
  8980. Node: Array Mapping
  8981. 294837
  8982. Node: Association Lists
  8983. 296754
  8984. Node: Byte
  8985. 299005
  8986. Node: Collections
  8987. 301236
  8988. Node: Dynamic Data Type
  8989. 307338
  8990. Node: Hash Tables
  8991. 308599
  8992. Node: Hashing
  8993. 310716
  8994. Node: Object
  8995. 315570
  8996. Node: Priority Queues
  8997. 333584
  8998. Node: Queues
  8999. 334506
  9000. Node: Records
  9001. 335632
  9002. Node: Structures
  9003. 339143
  9004. Node: Procedures
  9005. 340443
  9006. Node: Common List Functions
  9007. 341130
  9008. Node: List construction
  9009. 341554
  9010. Node: Lists as sets
  9011. 343217
  9012. Node: Lists as sequences
  9013. 348589
  9014. Node: Destructive list operations
  9015. 353834
  9016. Node: Non-List functions
  9017. 356497
  9018. Node: Tree Operations
  9019. 357845
  9020. Node: Chapter Ordering
  9021. 359391
  9022. Node: Sorting
  9023. 361011
  9024. Node: Topological Sort
  9025. 366788
  9026. Node: String-Case
  9027. 368475
  9028. Node: String Ports
  9029. 369096
  9030. Node: String Search
  9031. 369860
  9032. Node: Line I/O
  9033. 372227
  9034. Node: Multi-Processing
  9035. 374820
  9036. Node: Standards Support
  9037. 375903
  9038. Node: With-File
  9039. 376558
  9040. Node: Transcripts
  9041. 376834
  9042. Node: Rev2 Procedures
  9043. 377155
  9044. Node: Rev4 Optional Procedures
  9045. 378862
  9046. Node: Multi-argument / and -
  9047. 379432
  9048. Node: Multi-argument Apply
  9049. 380083
  9050. Node: Rationalize
  9051. 380569
  9052. Node: Promises
  9053. 381232
  9054. Node: Dynamic-Wind
  9055. 381649
  9056. Node: Eval
  9057. 382903
  9058. Node: Values
  9059. 386240
  9060. Node: Session Support
  9061. 387027
  9062. Node: Repl
  9063. 387508
  9064. Node: Quick Print
  9065. 388791
  9066. Node: Debug
  9067. 389904
  9068. Node: Breakpoints
  9069. 390546
  9070. Node: Trace
  9071. 392764
  9072. Node: System Interface
  9073. 394138
  9074. Node: Extra-SLIB Packages
  9075. 401331
  9076. Node: About SLIB
  9077. 403465
  9078. Node: Installation
  9079. 403908
  9080. Node: Porting
  9081. 405758
  9082. Node: Coding Standards
  9083. 407309
  9084. Node: Copyrights
  9085. 409387
  9086. Node: Index
  9087. 412712
  9088. End Tag Table
  9089.